-
C++ (
http://www.daniweb.com/forums/forum8.html)
| paeez | Mar 8th, 2007 4:53 am | |
| two array comparison 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?
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);
}
}
}
} |
| mathematician | Mar 8th, 2007 5:44 am | |
| Re: two array comparison The syntax of strcmp is strcmp( string1, string2 ) - not strcmp( string1/string2) |
| Ancient Dragon | Mar 8th, 2007 8:58 am | |
| Re: two array comparison inline code such a the remove() function should be limited to just one or two lines of code. Anything larger should be put in the implementation *.cpp file. |
| ~s.o.s~ | Mar 8th, 2007 1:14 pm | |
| Re: two array comparison Though I can pretty much bet that the given the kind of code inlined, the compiler will ignore his request for inlining... |
| All times are GMT -4. The time now is 2:24 am. | |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC