|
// Date: 2005/08/29 // Author: AOU // File: COOL003.cpp /* maintain Ordered Dense List, allow duplicate values Operations: create (COOL myList; ) populate (myList.populate(1,10);) populate (myList.populate(20);) populate (myList.populate("myList.dat");) shuffle (myList.shuffle();) insert (myList.insert(45);) deleteByValue (myList.delete(45);) display (a.display();) deleteAll sort sum (a = myList.sum();) */ int const MAX_SIZE = 20; int const UNDEFINED = -999; int const MIN_VALUE = -10; int const MAX_VALUE = 10; int const INFINITY = 9999; class COOL { private: int a[MAX_SIZE]; int n; public: COOL(void); void display(void); int insert(int x); int populate(int m); int populate(int n1, int n2); int populate(char *fileName); void shuffle(void); void sortBubble(void); bool deleteByPos(int p); int deleteByValue(int p); int deleteByValueAll(int p); int deleteByValueN(int p); int deleteByValueLast(int p); int sum(void); }; #include<iostream> using namespace std; void main () { COOL myList; myList.display(); } /* int COOL::insert(int x) inserts x into the list keeping it in order possibilities: (a) x is out of range (b) x is in range (c) list is empty (d) x >= the last value in the list (e) x < the first value in the list (f) x is between two values in the list Solutions: (a) add to the end and sort (b) four cases (c) start with dummy values and just one case Chosen start with dummy values and have just one case */ int COOL::insert(int x) { } void COOL::display(void) { cout << "COOL[" << n << "]: "; for (int i=0; i<=MAX_SIZE-1; i++) cout << a[i] << ' '; cout << endl; } COOL::COOL(void) { cout << "Default constructor is called\n"; for (int i=0; i<=MAX_SIZE-1; i++) a[i] = UNDEFINED; n = 0; } |