|
//file: CODL01.cpp //Author: AOU //Date 10/13/2004 // Ordered Dynamic Lisr //////////////////////////////////////////////////////// // includes //////////////////////////////////////////////////////// #include <iostream.h> #include <math.h> #include <stdlib.h> #include <time.h> #include <string.h> //////////////////////////////////////////////////////// // constants //////////////////////////////////////////////////////// int const MAX_SIZE = 20+2; int const INFINITY = 9999; int const TEST_COUNT = 20; int const MAX_VALUE = 10; int const MAX_LENGTH = 20+1; class CNode { private: char key[MAX_LENGTH]; CNode *next; public: CNode(void) { strcpy(key, ""); next = NULL; }; CNode(char value[]) { strcpy(key, value); next = NULL; }; void display(void) { cout << key; } friend class CODL; }; class CODL { private: CNode *head; int n; public: CODL(void) { CNode *p, *q; p = new CNode("$"); q = new CNode("z"); head = p; p->next = q; q->next = NULL; n = 0; } void display(void) { cout << "List[" << n << "] = "; CNode *p = head; while (p != NULL) { p->display(); cout << ' '; p = p->next; } cout << endl; } }; void main(void) { CODL od1; od1.display(); } |