Results 1 to 3 of 3

Thread: How to delete duplicate entries from string array

  1. #1
    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++?

  2. #2
    Join Date
    Apr 2008
    Posts
    2,005

    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.

  3. #3
    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];
    }
    }
    }

Similar Threads

  1. Removing duplicate entries from an array in VB
    By McKenzie! in forum Software Development
    Replies: 6
    Last Post: 27-07-2011, 11:47 AM
  2. Duplicate Calendar Entries
    By ksharkman in forum Windows Software
    Replies: 2
    Last Post: 08-04-2011, 12:36 AM
  3. How to prevent duplicate database entries
    By Zombi in forum Software Development
    Replies: 3
    Last Post: 25-09-2009, 02:59 PM
  4. How to Remove Duplicate Entries from Table ?
    By Faakhir in forum Software Development
    Replies: 3
    Last Post: 18-03-2009, 12:58 PM
  5. Replies: 0
    Last Post: 08-01-2009, 08:27 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,627,137.13966 seconds with 16 queries