TAILIEUCHUNG - Data Structures and Program Design in C++ phần 2

Hộp menu màu xanh lá cây ở lề bên trái của mỗi trang thực hiện nhảy đến các bộ phận được sử dụng thường xuyên của cuốn sách: biểu tượng Windows () ở lề trái lựa chọn và chạy một chương trình trình diễn, mà sẽ chỉ được hoạt động trên nền tảng Windows. CD này chứa một thư mục | Section Implementation of Stacks 57 Figure . Switching network for stack permutations IMPLEMENTATION OF STACKS _ We now turn to the problem of the construction of a stack implementation in C . contiguous We will produce a contiguous Stack implementation meaning that the entries are implementation stored next to each other in an array. In Chapter 4 we shall study a linked implementation using pointers in dynamic memory. In these and all the other implementations we construct we shall be careful classes always to use classes to implement the data structures. Thus we shall now develop a class Stack whose data members represent the entries of a stack. Before we implement any class we should decide on specifications for its methods. Specification of Methods for Stacks The methods of our class Stack must certainly include the fundamental operations stack methods called empty top push and pop . Only one other operation will be essential This is an initialization operation to set up an empty stack. Without such an initialization operation client code would have to deal with stacks made up of random and probably illegal data whatever happened beforehand to be in the storage area occupied by the stack. 1. Constructors The C language allows us to define special initialization methods for any class. These methods are called constructors for the class. Each constructor is a function with the same name as the corresponding class. A constructor has no return type. Constructors are applied automatically whenever we declare an object of the class. For example the standard library implementation of a stack includes a constructor that initializes each newly created stack as empty In our earlier program for reversing a line of input such an initialization was crucial. Naturally we shall create a similar Stack constructor for the class that we develop. Thus whenever one of our clients declares a Stack object that object is automatically .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.