police45s
asked on
C++, sorting an array and dumping duplicate values
I have an array that was bubble sorted alphabetically. Now I have the array but have duplicate values. I want to print out the array but not print the duplicate values. We are about 4 weeks into the course so I'm hoping the solution is not too complex
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
int nArraySize = 250;
int* pArray = new int[nArraySize]; //the array with some values
// your sorting goes here
int nOldValue;
int nNewValue;
for( int i=0 ; i<nArraySize ; i++ )
{
nNewValue = pArray[i];
bool bWrite = (i==0); //first value is always written
if( bWrite==false ) //if not the first, check if new value is the same
{
bWrite = (nNewValue!=nOldValue);
}
if( bWrite )
{
cout << nNewValue << endl;
}
nOldValue = nNewValue; //remember last value written
}
int* pArray = new int[nArraySize]; //the array with some values
// your sorting goes here
int nOldValue;
int nNewValue;
for( int i=0 ; i<nArraySize ; i++ )
{
nNewValue = pArray[i];
bool bWrite = (i==0); //first value is always written
if( bWrite==false ) //if not the first, check if new value is the same
{
bWrite = (nNewValue!=nOldValue);
}
if( bWrite )
{
cout << nNewValue << endl;
}
nOldValue = nNewValue; //remember last value written
}
i = 0
j = i + 1
For loop = 0 to ARRAY_SIZE {
If (arr(j) != arr(i)){
Print arr(i)
i = j
}
j++
}