| | |
two array comparison
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2007
Posts: 7
Reputation:
Solved Threads: 0
I want to search a name in my doubly linkedlist and remove it.
I used strcmp(string1/string2) to see if the data part of the current node is the same as the data im looking for or not.but it didnt work.
what can i do?
I used strcmp(string1/string2) to see if the data part of the current node is the same as the data im looking for or not.but it didnt work.
what can i do?
class node {
friend class linklist;
char name[10];
node *nxt;
node *prev;
void remove(char nam[]){
node *ptr;
ptr=head;
if(head == NULL){//the list is empty
cout<<"the list is empty"<<endl;
}
else{
while(ptr !=NULL )//till it hasnt got to the end and didnt find the number
{ if(strcmp(ptr ->name/ nam)!=0) {ptr=ptr ->nxt;}}
if(ptr ==NULL)//it means that the number is not in the list
{cout<<"the name is not in the list to remove."<<endl;}
else if(ptr != NULL)// it means that the number is found
{ if(head == ptr) //if removing head node
{ if(head == tail){//if there is only one node in the list
head=NULL;
delete(ptr);
}
else{ head=head -> nxt;
head -> prev = NULL;
delete(ptr);}
}
else if(tail == ptr)
{ // if removing tail node
tail = tail->prev;
tail->nxt = NULL;
delete(ptr);
}
else {
// if removing in the middle
ptr->prev->nxt = ptr->nxt;
ptr->nxt->prev = ptr->prev;
delete(ptr);
}
}
}
} Though I can pretty much bet that the given the kind of code inlined, the compiler will ignore his request for inlining...
I don't accept change; I don't deserve to live.
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
![]() |
Similar Threads
- Anyone can do this in C++ (C++)
- Question about reversal and array storage for Palindrome (C++)
- How to Sort a MultiDimensional Array (C)
- I'm new in this site and also in c++, please help me (C++)
- array / data comparision help (C)
- How do I create a program using an Array ? (C++)
Other Threads in the C++ Forum
- Previous Thread: How do I read the registry?
- Next Thread: chinese ascii
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamiccharacterarray email encryption error file format forms fstream function functions game givemetehcodez graph gui homeworkhelp iamthwee ifstream input int java lib library lines list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg simple sorting spoonfeeding string strings struct temperature template templates text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






