how to delete duplicate record...

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2006
Posts: 4
Reputation: bh_hensem is an unknown quantity at this point 
Solved Threads: 0
bh_hensem bh_hensem is offline Offline
Newbie Poster

how to delete duplicate record...

 
1
  #1
Sep 4th, 2006
Hello,

Could some body help me how could i delete any duplicate or same record of the input ?

This is my plan but i am not sure it si working with C++ or not :-
My program will be pass "number" values to this function and the function will be find out all the match number from the numbering list (mCUGParameter variables) and save it into array. Finally the function will be delete any duplicate record of the array and print it.

Example of numbering list:-
#Input or number=group,date1,date2
01200485=31595,20060307120553,
01200485=31595,20060307120553,
01940403=31595,20060307120553,
01940403=31595,20060307120553,
01940403=31595,20060307120553,20060607120553

Expected result:-
01200485=31595,20060307120553,
01940403=31595,20060307120553,
01940403=31595,20060307120553,20060607120553

Then, i do not know how could i delete any duplicate input here... could somebody help me ?

or is it ok with my steps or my ideas ?

  1.  
  2. bool getCUGParameter(const G_String& number, int *cugIndex,
  3. int *createTS, int *terminateTS)
  4. {
  5. int mycharstr[100];
  6. int mycharstr1[30];
  7. int mycharstr2[30];
  8. int mycharstr3[30];
  9. G_DynArray<Parameter> matchedstrlist;
  10. G_String matchedstr;
  11. G_String lookupvalue;
  12. int numofmatchedstr;
  13.  
  14. memset(mycharstr, '\0', sizeof(mycharstr));
  15. memset(mycharstr1, '\0', sizeof(mycharstr1));
  16. memset(mycharstr2, '\0', sizeof(mycharstr2));
  17. memset(mycharstr3, '\0', sizeof(mycharstr3));
  18.  
  19. // find all matches number from mCUGParameter
  20. matchedstrlist = mCUGParameter.findMultipleMatchesWithoutEIgnoreSpace(number);
  21. numofmatchedstr = matchedstrlist.size();
  22.  
  23. if (numofmatchedstr > 0) {
  24. int m;
  25. for (m=0; m <= numofmatchedstr; m++) {
  26. lookupvalue=matchedstrlist[m].getValue();
  27. removeBlank(lookupvalue);
  28. sscanf(lookupvalue.cStr(), "%s", mycharstr);
  29.  
  30. int i = 0;
  31. int j = 0;
  32. int k = 0;
  33.  
  34. for (i=0; mycharstr[i] != '\0'; i++) {
  35. if (mycharstr[i] == ',') {
  36. j++;
  37. k = 0;
  38. } else {
  39. if (j == 0) {
  40. mycharstr1[k] = mycharstr[i];
  41. } else if (j == 1) {
  42. mycharstr2[k] = mycharstr[i];
  43. } else if (j ==2) {
  44. mycharstr3[k] = mycharstr[i];
  45. } else {
  46. // do nothing
  47. }
  48. k++;
  49. }
  50. cugIndex[m] = mycharstr1[k];
  51. createTS[m] = mycharstr2[k];
  52. terminateTS[m] = mycharstr3[k];
  53. }
  54. }
  55.  
  56. for (m=0; m < numofmatchedstr; m++) {
  57. cout << "TEST: " << cugIndex[m] << " - " << createTS[m] << " - " << terminateTS[m] << endl;
  58. }
  59. return true;
  60. } else {
  61. return false;
  62. }
  63. }
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,619
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 468
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: how to delete duplicate record...

 
1
  #2
Sep 5th, 2006
The algorithm for cleaning out duplicates from a dynamic array has the following procedure:

1) Store the current record in the variable.
2) Using a compare function, compare the current variable with each and every variable of the dynamic array storing the records.
3) Whenever a match is found, delete that record (if your dynamic array is implemented using linked lists then you can use the concept of linked list deletion).
4) Keep continuining till more records are found.

Hope it helped, bye.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 4
Reputation: bh_hensem is an unknown quantity at this point 
Solved Threads: 0
bh_hensem bh_hensem is offline Offline
Newbie Poster

Re: how to delete duplicate record...

 
1
  #3
Sep 5th, 2006
the problem is how could i store the current record in the variable ? Can you give some example ?

I have tried it before but the previous input have been overwrited...
Last edited by bh_hensem; Sep 5th, 2006 at 2:56 am.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: how to delete duplicate record...

 
1
  #4
Sep 5th, 2006
Originally Posted by bh_hensem View Post
the problem is how could i store the current record in the variable ? Can you give some example ?

I have tried it before but the previous input have been overwrited...
Did you read in the current record? Is it still in the variable space? If so, move it to a new variable (maybe called LastRec) just before you go back to read the next record from the user.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 488
Reputation: Bench has a spectacular aura about Bench has a spectacular aura about Bench has a spectacular aura about 
Solved Threads: 49
Bench's Avatar
Bench Bench is offline Offline
Posting Pro in Training

Re: how to delete duplicate record...

 
1
  #5
Sep 5th, 2006
Since you're using C++, have you done any research into STL and the standard library algorithms? these sorts of tasks are exactly the kind of thing which the STL excels at doing - eg,
#include <iostream>
#include <vector>
#include <algorithm>

template<const int N>
int array_size(const int (&arr)[N] )
{ 
    return N;
}

int main()
{
    typedef std::vector<int>::iterator iter_t;

//Just for the purpose of this example, populating
// an STL vector container using an array initialiser.
    const int lookup_table[] = { 2,3,5,5,11,13,11 } ;
    std::vector<int> my_vec(lookup_table, 
                            lookup_table + array_size(lookup_table) );

//Sorting all elements in the container:
// Make sure that all elements in the container are in order
// so that std::unique can identify all duplicates.
    std::sort(my_vec.begin(), my_vec.end());

    iter_t new_end;
    new_end = std::unique(my_vec.begin(),
                          my_vec.end() );

//Now the container is too big and has some unwanted data at the end
// lets get rid of those unwanted elements.
    my_vec.erase(new_end, my_vec.end());

    for( iter_t it = my_vec.begin(); it != my_vec.end(); ++it)
        std::cout << *it << std::endl;
} 
Last edited by Bench; Sep 5th, 2006 at 7:14 pm.
¿umop apisdn upside down?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC