943,739 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1947
  • C++ RSS
Mar 8th, 2007
0

two array comparison

Expand Post »
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);
        }
     }
    }
  }
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
paeez is offline Offline
11 posts
since Feb 2007
Mar 8th, 2007
0

Re: two array comparison

The syntax of strcmp is strcmp( string1, string2 ) - not strcmp( string1/string2)
Reputation Points: 14
Solved Threads: 4
Junior Poster
mathematician is offline Offline
149 posts
since Nov 2006
Mar 8th, 2007
0

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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,950 posts
since Aug 2005
Mar 8th, 2007
0

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...
Super Moderator
Featured Poster
Reputation Points: 3233
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,871 posts
since Jun 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: How do I read the registry?
Next Thread in C++ Forum Timeline: chinese ascii





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC