|
//file : p015.cpp //author: AOU //date : 07/22/2004 ///////////////////////////////////////////////// ///////////////////////////////////////////////// #include <iostream.h> #include <stdlib.h> #include <time.h> ///////////////////////////////////////////////// ///////////////////////////////////////////////// const int ARRAY_SIZE = 10; const int MIN_VALUE = 0; const int MAX_VALUE = 6; const int TEST_COUNT = 20; ///////////////////////////////////////////////// ///////////////////////////////////////////////// void testAll(void); void test_populate(void); void test_sortBubble(void); void test_isSorted(void); void test_constructor_n(void); void test_constructor_r(void); void test_constructor_s(void); void test_constructor_d(void); void test_has(void); void test_hasDistinctValues(void); void test_shuffle(void); void test_shuffle_friend(void); void test_isEqualTo_friend(void); void test_constructor_copy(void); void test_isEqualTo_member(void); void test_isEqualTo_operator(void); void test_isNotEqualTo_operator(void); void test_deleteAtPos(void); void test_purgeDupes(void); void test_operator_plus(void); void test_operator_subset(void); void test_operator_intersection(void); void test_operator_union(void); void test_operator_minus(void); ///////////////////////////////////////////////// ///////////////////////////////////////////////// class CNode { private: int info; CNode *next; public: CNode(void); CNode(int x); friend class CArray; }; ///////////////////////////////////////////////// ///////////////////////////////////////////////// class CArray { private: int n; CNode *head; CNode *tail; public: CArray(void); bool insertAtTail(int x); void display(void); }; ///////////////////////////////////////////////// ///////////////////////////////////////////////// void main(void) { CArray ta; ta.display(); ta.insertAtTail(5); ta.display(); ta.insertAtTail(2); ta.display(); ta.insertAtTail(4); ta.display(); ta.insertAtTail(9); ta.display(); } ///////////////////////////////////////////////// ///////////////////////////////////////////////// void CArray::display(void) { cout << "[" << this->n << " ]= "; CNode * p; p = this->head; while (p != NULL) { cout << p->info << ' '; p = p->next; } cout << endl; } ///////////////////////////////////////////////// ///////////////////////////////////////////////// bool CArray::insertAtTail(int x) { CNode *p; p = new CNode; p->info = x; p->next = NULL; if (this->head == NULL) this->head = this->tail = p; else { this->tail->next = p; this->tail = p; } this->n++; return true; } ///////////////////////////////////////////////// ///////////////////////////////////////////////// CArray::CArray(void) { this->n = 0; this->head = NULL; this->tail = NULL; } ///////////////////////////////////////////////// ///////////////////////////////////////////////// CNode::CNode(void) { this->info = 0; this->next = NULL; } ///////////////////////////////////////////////// ///////////////////////////////////////////////// CNode::CNode(int x) { this->info = x; this->next = NULL; } /* Output: [0 ]= [1 ]= 5 [2 ]= 5 2 [3 ]= 5 2 4 [4 ]= 5 2 4 9 Press any key to continue */ |