Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 02-09-2009
Member
 
Join Date: Jun 2009
Posts: 87
How to delete duplicate entries from string array

I want to create a small C++ program where user inputs an array and the compiler finds all the duplicates from that array and delete. And finally the result is presented to user with unique entries in the array. I know how to input the array but the code to delete the duplicates in in disguise. Can some one provide me atleast the logic of deleting the duplicates from string array in C++?
Reply With Quote
  #2  
Old 02-09-2009
Member
 
Join Date: Apr 2008
Posts: 2,001
Re: How to delete duplicate entries from string array

If you just want the code then the concept is quiet is easy. Basically what you need to do is first sort the array. I hope you know how to sort the array. Then run a for loop where you check if the first array element is equal to second array element. For example, a[i] = a[i+1]. If this is true then delete the second one and move to next.
Reply With Quote
  #3  
Old 02-09-2009
Member
 
Join Date: Nov 2008
Posts: 996
Re: How to delete duplicate entries from string array

I think the below example should give you some idea of how to delete the duplicated entries in sorted array:

Code:
void main()
{
int i,j;
int temp=0;
bool counter;
string str[];
// input and sort the array
for(i=0; i<=str.lastElement; i++)
{
counter=false;
if(str[i] == str[i+1])
{
counter=true; 
temp++; 
}
for(j=i-temp;j<=str.lastElement;j++)
{
str[j] = str[j+temp];
}
}
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to delete duplicate entries from string array"
Thread Thread Starter Forum Replies Last Post
Removing duplicate entries from an array in VB McKenzie! Software Development 6 27-07-2011 11:47 AM
Duplicate Calendar Entries ksharkman Windows Software 2 08-04-2011 12:36 AM
How to prevent duplicate database entries Zombi Software Development 3 25-09-2009 02:59 PM
How to Remove Duplicate Entries from Table ? Faakhir Software Development 3 18-03-2009 12:58 PM
Delete duplicate emails and posts in Outlook with Duplicate Email Remover 2.15.2 Pyrotechnic Windows Software 0 08-01-2009 08:27 AM


All times are GMT +5.5. The time now is 11:50 PM.