//**************************************************************************** // Programmer: Sriram Pemmaraju // Date: 9/2/2002 // This class implements a primitive list that provides a few simple // member functions including a function for removing duplicates. //**************************************************************************** #include #include #include #include "SmallList.h" using namespace std; const int SmallList::MAX_SIZE; void SmallList::readNumbers(int size){ assert(size <= MAX_SIZE); for(int i = 0; i < size; i++) cin >> myList[i]; mySize = size; } void SmallList::sort(){ for(int i = 0; i <= mySize-2 ; i++) for(int j = mySize-2; j >=i; j--){ if(myList[j] > myList[j+1]){ int t = myList[j]; myList[j] = myList[j+1]; myList[j+1] = t; } } } void SmallList::removeDuplicates(){ (*this).sort(); int current = myList[0]; int count = 0; for(int i = 1; i < mySize; i++){ if (myList[i] == current) count++; else{ current = myList[i]; myList[i-count] = myList[i]; } } mySize = mySize - count; } int SmallList::size() const{ return mySize; } void SmallList::writeNumbers(){ for(int i = 0; i < mySize; i++) cout << myList[i] << endl; }