📄 list.h
字号:
//// ********************************************************************// *// * Author : Gerald Carter// * cartegw@humsci.auburn.edu// * Filename : list.h// * Date Created : 961220// *// * Description// * -------------// * This is the header file for a C++ linked list template// *// * -------------// * Modifications// * -------------// *// *******************************************************************//// INCLUDE FILES#include <iostream.h>#include "logic.h"#include "link.h"#ifndef _LIST_H#define _LIST_H#pragma interface// ###################################################################// ## class linkedListNode// ##// macros for indexing pointers in link class#define NEXT 0#define PREVIOUS 1template <class T, int size>class linkedListNode : public nodeLink<size> { private : T data; public : // CONSTRUCTORS linkedListNode ( void ) { SetLink ( NEXT, 0 ); SetLink ( PREVIOUS, 0 ); } linkedListNode ( const T& item, nodeLink<2>* pt1=0, nodeLink<2>* pt2=0 ) { data = item; SetLink ( NEXT, pt1 ); SetLink ( PREVIOUS, pt2 ); } // GENERAL METHODS void SetData (const T& item) { data = item; } T GetData (void) { return data; } };// ###################################################################// ## class List// ##template <class T>class list { private : linkedListNode<T,2> *front; // first node in list linkedListNode<T,2> *end; // last node in list int node_count; // number of nodes in list public : list ( void ); // no nodes in list list ( const T& ); // add first string to list list ( const list<T>& ); // allocation and assignment ~list ( void ); // destructor list<T>& Add ( const list<T>& ); // catenates 2 lists list<T>& Add ( const T& ); // add string to end of list list<T>& Remove ( const T& ); // subtract 1st T from list if present list<T>& Sort ( void ); list<T>& operator= ( const list& ); // allocation and assignment T operator[] ( int ) const; // returns allocated string from list int operator[] ( const T& ); // returns index of T in list (0...n) void PrintList ( ostream& ); T First ( void ); T Last ( void ); boolean IsEmpty ( void ) const { return ( node_count == 0 ); } int SizeOf ( void ) const { return ( node_count ); }}; // end of list class#endif//************** end of list.h *****************************************//**********************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -