two array comparison

Reply

Join Date: Feb 2007
Posts: 7
Reputation: paeez is an unknown quantity at this point 
Solved Threads: 0
paeez paeez is offline Offline
Newbie Poster

two array comparison

 
0
  #1
Mar 8th, 2007
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);
        }
     }
    }
  }
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 134
Reputation: mathematician is an unknown quantity at this point 
Solved Threads: 3
mathematician mathematician is offline Offline
Junior Poster

Re: two array comparison

 
0
  #2
Mar 8th, 2007
The syntax of strcmp is strcmp( string1, string2 ) - not strcmp( string1/string2)
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,161
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1438
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: two array comparison

 
0
  #3
Mar 8th, 2007
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.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,581
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: 461
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: two array comparison

 
0
  #4
Mar 8th, 2007
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.
Reply With Quote Quick reply to this message  
Reply

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


Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC