Absolute C++ (4th Edition) part 73

Absolute C++ (4th Edition) part 73. KEY BENEFIT: C++ programming concepts and techniques are presented in a straightforward style using understandable language and code. KEY TOPICS: C++ Basics; Flow of Control; Function Basics; Parameters and Overloading; Arrays; Structures and Classes; Constructors; Operator Overloading, Friends, and References; Strings; Pointers and Dynamic Arrays; Separate Compilation and Namespaces; Streams and File I/O; Recursion; Inheritance; Polymorphism and Virtual Functions; Templates; Linked Data Structures; Exception Handling; Standard Template Library; Patterns and UML. MARKET: Useful for both beginning and intermediate C++ programmers. . | Linked List Applications 727 Display A Queue Template Class as a Friend of the Node Class part 1 of 2 1 2 This is the header file . This is the interface for the class 3 Queue which is a template class for a queue of items of type T. 4 ifndef QUEUE_H 5 define QUEUE_H 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 template class T class Queue template class T class Node public namespace QueueSavitch A forward declaration. Do not forget the semicolon. This is an alternate approach to that given in Display . In this version the Queue template class is a friend of the Node template class. Node T theData Node T friend class Queue T private T data Node T link template class T class Queue theLink data theData link theLink If Node T is only used in the definition of the friend class Queue T there is no need for mutator or accessor functions. The definition of the template class Queue is identical to the one given in Display . However the definitions of the member functions will be different from the ones we gave in the Self-Test Exercises for the nonfriend version of Queue. QueueSavitch endif QUEUE_H 29 30 31 32 33 34 35 36 37 38 39 iostream cstdlib cstddef include include include include using std cout namespace QueueSavitch The implementation file would contain these definitions and the definitions of the other member functions similarly modified to allow access by name to the link and data member variables of the nodes. template class T Uses cstddef void Queue T add T item if isEmpty 728 Linked Data Structures Display A Queue Template Class as a Friend of the Node Class part 2 of 2 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 front back new Node T item NULL else back- llnk new Node T ltem NULL back back- llnk If efficiency is a major issue you might want to use front NULL instead of isEmpty . template class T Uses cstdllb and lostream T Queue T remove lf lsEmpty cout Error Removlng an .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
Đã 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.