need help with functions using array

we are creating a array to output intergers in increasing order, i have a problem with when the result outputs i dont want it to tell the repeated number, i think something is wrong with the functions that are bold faced. for example i input 999987654321, it will show 123456789999, it should be 123456789, so help please with three function of removing the entry......


int getNumber(){
int number (-2);

while( number < -1 || number > 100 ){
cout << "Enter a number greater than 0 and less or equal to 100 ";
cin >> number;

if ( number < -1 || number > 100 ){
cout << endl;
cout << "You did not enter a number between 0..100 inclusive." << endl;
cout << "Let's try again." << endl;
cout << endl;
}
}
return number;
}

int min ( int table[], int length){
int min(table[0]);
int i(1);

while ( i <= length){
if (table[i] < min)
min = table[i];
i = i + 1;
}

return min;
}

void swap( int table[], int i , int j ) {
int t = table[i];
table[i] = table[j];
table[j] = t;
}

void removeEntryAt( int table[], int & length, int cmPos ) {
int i(cmPos);

while ( 1 < length - 1 ){
table[i] = table[ i + 1 ];
i = i + 1;
}
length = length - 1;
}


int indexof( int table[], int length, int cmPos ) {
int i(0);
int result(i);

while( i < length && table[i] != cmPos ) {
if( i < length )
result = i;
}
return result;
}


void removeEntry( int table[], int & length, int cmPos ) {

int pos = indexof(table, length, cmPos);
if( pos != -1 )
removeEntryAt( table, length, cmPos);
}


int posofSmallest( int table[], int length, int first ) {
int cmPos(first);
int i(first + 1);

while( i <= length ) {
if( table[i] < table[cmPos] )
cmPos = i ;
i = i + 1 ;
}
return cmPos;
}

void selectionSort( int table[], int length) {
int i(0);
int pos;

while ( i <= length - 1 ) {
pos = posofSmallest( table, length, i );
swap( table[i], table[pos]);
i = i + 1;
}
}

void outputTable( int table[], int length){

cout << endl;
int i (0);

while( i <= length ){
cout << "Table[" <<i<<"] : " ;
cout << table[i] << endl;
i = i + 1;
}
cout << endl;
}

void readTable(int table[], int size, int &length){
int number(0);
int index(0);

number = getNumber();

while ( index < size && number > 0){
table[index] = number;
index = index + 1;
if (index <= size - 1)
number = getNumber();
}

length = index - 1;
}


int main(){
int length(0);
int table[20];
int cmPos(0);

readTable( table, 20, length);

cmPos = min( table, length );

outputTable( table, length);

selectionSort(table, length);

removeEntry( table, length, cmPos);

outputTable( table, length);

system("Pause");
return 0;
}


cmPos is 0. I don't see what purpose it serves..

You want to erase duplicate entries? There's a function http://www.cplusplus.com/reference/algorithm/unique/ to do that. There is a rather intelligent example implementation shown too.
Topic archived. No new replies allowed.