Solved

C++, sorting an array and dumping duplicate values

Posted on 2004-09-27
3
435 Views
Last Modified: 2010-05-18
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
0
Comment
Question by:police45s
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 2

Accepted Solution

by:
pek99 earned 125 total points
ID: 12164721
when dumping the array of strings, remember the pointer of the previously printed one, make strcmp, or other string
comparation with the current string and print only when it is different.
0
 
LVL 4

Expert Comment

by:avi247
ID: 12165161
Heres a pseudo code..assuming the array is sorted.


   i = 0
   j = i + 1

 For loop = 0 to ARRAY_SIZE {
    If (arr(j) != arr(i)){
      Print arr(i)
      i = j        
    }
     j++      
  }
 
0
 
LVL 2

Expert Comment

by:Ruskialt
ID: 12225619
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
}
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question