•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 402,762 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,704 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 3993 | Replies: 4
![]() |
•
•
Join Date: Sep 2006
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
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 ?
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 ?
bool getCUGParameter(const G_String& number, int *cugIndex,
int *createTS, int *terminateTS)
{
int mycharstr[100];
int mycharstr1[30];
int mycharstr2[30];
int mycharstr3[30];
G_DynArray<Parameter> matchedstrlist;
G_String matchedstr;
G_String lookupvalue;
int numofmatchedstr;
memset(mycharstr, '\0', sizeof(mycharstr));
memset(mycharstr1, '\0', sizeof(mycharstr1));
memset(mycharstr2, '\0', sizeof(mycharstr2));
memset(mycharstr3, '\0', sizeof(mycharstr3));
// find all matches number from mCUGParameter
matchedstrlist = mCUGParameter.findMultipleMatchesWithoutEIgnoreSpace(number);
numofmatchedstr = matchedstrlist.size();
if (numofmatchedstr > 0) {
int m;
for (m=0; m <= numofmatchedstr; m++) {
lookupvalue=matchedstrlist[m].getValue();
removeBlank(lookupvalue);
sscanf(lookupvalue.cStr(), "%s", mycharstr);
int i = 0;
int j = 0;
int k = 0;
for (i=0; mycharstr[i] != '\0'; i++) {
if (mycharstr[i] == ',') {
j++;
k = 0;
} else {
if (j == 0) {
mycharstr1[k] = mycharstr[i];
} else if (j == 1) {
mycharstr2[k] = mycharstr[i];
} else if (j ==2) {
mycharstr3[k] = mycharstr[i];
} else {
// do nothing
}
k++;
}
cugIndex[m] = mycharstr1[k];
createTS[m] = mycharstr2[k];
terminateTS[m] = mycharstr3[k];
}
}
for (m=0; m < numofmatchedstr; m++) {
cout << "TEST: " << cugIndex[m] << " - " << createTS[m] << " - " << terminateTS[m] << endl;
}
return true;
} else {
return false;
}
} 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.
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."
"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
•
•
•
•
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.
Age is unimportant -- except in cheese
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 6:14 pm.
¿umop apisdn upside down? ![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- how to delete duplicate record in a table by using SQL query (MS SQL)
- Delete related record (VB.NET)
Other Threads in the C++ Forum
- Previous Thread: Constructor troubles
- Next Thread: how to convert NFA to DFA in c



Linear Mode