Thread: Need help with C++ linked list using objects

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    18

    Need help with C++ linked list using objects

    Here is what I have so far. The spec sheet the professor handed out was very strict. It only specifies what the member functions and classes will contain, no main() or program function info. I am having a hard time figuring out how to get the add member function to work. It receives a pointer to a node but how do I get the value passed to set in the data attribute? I assume it would be in the main() call of L1.add(int);

    A little confused need help with this and I'm sure with a few more things, only have a few days left before the semester is over . THANKS!


    Code:
     
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    //******************CLASS NODE*****************// 
    class node
    {
         private:
              int data;
              node *next;
         public:
              node(int);
              node *getNext();
              void setNext(node *);
              void setData(int);
              int getData();
    
    };
    
    
    node::node(int value)
    {
         data = value;
         next = '\0';     
    }
    
    node * node::getNext()
    {
         return next;
    }
    
    void node::setNext(node *newNodePtr)
    {
        next = newNodePtr;     
    }
    
    void node::setData(int value)
    {
         data = value;
    }
    
    int node::getData()
    {
         return data;
    } 
    //***********END OF CLASS NODE*****************//
    
    
    //************CLASS LISTCONTROLLER*************//
    
    class listController
    {
         private:
              int count;
              node *head;
              node *tail;
         public:
              listController();
              listController(const listController &);
              ~listController();
              void add(node *);
              int getCount();
              void printList();
              node *deleteNode(int);
              int deleteAllSpecific(int);
              int deleteAll();
              node *searchList(int);
              int isEmpty();
    };
    
    
    listController::listController()
    {
         count = 0;
         *head = '\0';
         *tail = '\0';
    }
    
    listController::listController(const listController &Copy)
    {
    }
    
    listController::~listController()
    {
    }
    
    void listController::add(node *newNodePtr)
    {     
         class node *currNodePtr = NULL;
         
         newNodePtr = new node();
         
         if(head == NULL)//no nodes
         {
              head = newNodePtr;
              tail = newNodePtr;
         }
         else
         {
              tail->setNext(newNodePtr);
              tail = newNodePtr;
         }     
         
    }
    
    int listController::getCount()
    {
         return count;
    }
    
    void listController::printList()
    {
         class node *currNodePtr = NULL;
         
         currNodePtr = head;
         
         while(currNodePtr->getNext() != NULL)
         {
              cout<<currNodePtr->getData()<<endl;
              currNodePtr->setNext(currNodePtr);
         }     
         
    }
    
    node * listController::deleteNode(int value)
    {
         class node *currNodePtr = NULL;
         class node *prevNodePtr = NULL;
         
         currNodePtr = head;
         prevNodePtr = head;
                                                 //loop until value is found
         while(currNodePtr != NULL && currNodePtr->getData() != value)
         {
              prevNodePtr = currNodePtr;
              currNodePtr = currNodePtr->getNext();
         }
         
         if(currNodePtr->getData() == value)
         {
              if(currNodePtr == head)            //if value found is first node
              {
                   head = currNodePtr->getNext();
              }
              else if(currNodePtr == tail)       //if value found is last node
              {
                   tail = prevNodePtr;
                   prevNodePtr->setNext(NULL);
              }
              else                               //if value found is somewhere in between
              {
                   prevNodePtr->setNext(currNodePtr->getNext());
              }
              
              count--;
         }    
         
         return currNodePtr;     
    } 
    
    int listController::deleteAllSpecific(int value)
    {
         class node *currNodePtr = NULL;
         class node *prevNodePtr = NULL;
         class node *tempNodePtr = NULL;
         
         int nodesDeleted = 0;
         
         currNodePtr = head;
         prevNodePtr = head;
                                                      //loop until null
         while(currNodePtr != NULL)
         {
              if(currNodePtr->getData() == value)
              {
                   if(currNodePtr == head)            //if value found is first node
                   {
                        head = currNodePtr->getNext();
                        prevNodePtr = currNodePtr->getNext();
                   }
                   else if(currNodePtr == tail)       //if value found is last node
                   {
                        tail = prevNodePtr;
                        prevNodePtr->setNext(NULL);
                   }
                   else                               //if value found is somewhere in between
                   {
                        prevNodePtr->setNext(currNodePtr->getNext());
                   }
                   
                   nodesDeleted++;
                   count--;               
                   tempNodePtr = currNodePtr;               
                   currNodePtr = currNodePtr->getNext();                
    
                   delete(tempNodePtr);          //free node memory           
              }
              else                               //advance pointers
              {
                   prevNodePtr = currNodePtr;
                   currNodePtr = currNodePtr->getNext();
              }
         }
         
         return nodesDeleted;
    }
    
    int listController::deleteAll()
    {
         class node *currNodePtr = NULL;
         class node *tempNodePtr = NULL;
         
         int nodesDeleted = 0;
         
         currNodePtr = head;
         
         while(currNodePtr != NULL)
         {          
              tempNodePtr = currNodePtr;
              currNodePtr = currNodePtr->getNext(); 
              head = currNodePtr;
              
              if(currNodePtr == NULL)
              {
                   tail = head;
              }
              
              nodesDeleted++;          
              count--;
              
              delete(tempNodePtr);     
         }
         
         return nodesDeleted;     
    }
    
    node * listController::searchList(int value)
    {     
         class node *currNodePtr = NULL;
         
         currNodePtr = head;
         
         while(currNodePtr != NULL && currNodePtr->getData() != value)
         {
              currNodePtr = currNodePtr->getNext();
         }
         
         return currNodePtr;
         
    }
    
    int listController::isEmpty()
    {
         int flag = 1;
         
         if(count > 0)
         {
              flag = 0;
         }
         
         return flag;
    }
       
         
    
    
    //*********END OF CLASS LISTCONTROLLER*********//
    
    
    //***********************MAIN******************//
    int main()
    {    
         listController L1;
         
         system("PAUSE");
         return(0);    
         
         
    }
    //*****************END OF MAIN*****************//

  2. #2
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    > newNodePtr = new node();

    Your re-assigning the variable passed to your function with a new, blank node.

  3. #3
    Registered User
    Join Date
    Mar 2005
    Posts
    18
    Quote Originally Posted by Perspective
    > newNodePtr = new node();

    Your re-assigning the variable passed to your function with a new, blank node.

    I know, this is where I got confused. So should I not be generating a new node? Thats why based on the function params would I be doing such a thing or I wonder if the professors main() will be generating a new node and then passing it? Thoughts? Advice, before I go nuts Thanks.

  4. #4
    Registered User
    Join Date
    Feb 2006
    Posts
    312
    Based on my biased experience of how the STL list works, I would say that your add function should accept the data to be stored inside the parenthesis, and let the function create the new node. Ideally, the user of the linked list class should not need to worry about creating new nodes, since that's a class implementation detail IMHO.

  5. #5
    Registered User
    Join Date
    Mar 2005
    Posts
    18
    Quote Originally Posted by Bench82
    Based on my biased experience of how the STL list works, I would say that your add function should accept the data to be stored inside the parenthesis, and let the function create the new node. Ideally, the user of the linked list class should not need to worry about creating new nodes, since that's a class implementation detail IMHO.

    I know thats how I have been doing it but the professor in this assignment seems to be getting a little sneeky It looks as if he is making the node somewhere in HIS main() and passing it to the class member functions he wants us to build. Here is what I have so far. Anyone mind checking over my functions to make sure they look right? Thanks.


    Code:
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    //******************CLASS NODE*****************// 
    class node
    {
         private:
              int data;
              node *next;
         public:
              node(int);
              node *getNext();
              void setNext(node *);
              void setData(int);
              int getData();
    
    };
    
    
    node::node(int value)
    {
         data = value;
         next = '\0';     
    }
    
    node * node::getNext()
    {
         return next;
    }
    
    void node::setNext(node *newNodePtr)
    {
        next = newNodePtr;     
    }
    
    void node::setData(int value)
    {
         data = value;
    }
    
    int node::getData()
    {
         return data;
    } 
    //***********END OF CLASS NODE*****************//
    
    
    //************CLASS LISTCONTROLLER*************//
    
    class listController
    {
         private:
              int count;
              node *head;
              node *tail;
         public:
              listController();
              listController(const listController &);
              ~listController();
              void add(node *);
              int getCount();
              void printList();
              node *deleteNode(int);
              int deleteAllSpecific(int);
              int deleteAll();
              node *searchList(int);
              int isEmpty();
    };
    
    
    listController::listController()
    {
         count = 0;
         *head = '\0';
         *tail = '\0';
    }
    
    listController::listController(const listController &Copy)
    {
         count = Copy.count;
         head = new node(*(Copy.head));
         tail = new node(*(Copy.head));
    }
    
    listController::~listController()
    {
         class node *currNodePtr = NULL;
         class node *tempNodePtr = NULL;
       
         currNodePtr = head;
         
         while(currNodePtr != NULL)
         {          
              tempNodePtr = currNodePtr;
              currNodePtr = currNodePtr->getNext(); 
              head = currNodePtr;
              
              if(currNodePtr == NULL)
              {
                   tail = head;
              }
              
              delete(tempNodePtr);     
         }
         
    }
    
    void listController::add(node *newNodePtr)
    {     
         class node *currNodePtr = NULL;
         class node *prevNodePtr = NULL;
         
         currNodePtr = head;
         prevNodePtr = head;      
         
         if(head == NULL)                        //no nodes (first node to add)
         {
              head = newNodePtr;
              tail = newNodePtr;
         }          
         else
         {
              while(currNodePtr != NULL && currNodePtr->getData() >= newNodePtr->getData())
              {   
                   prevNodePtr = currNodePtr;
                   currNodePtr = currNodePtr->getNext();
              }               
              if(prevNodePtr == tail)            //add to rear
              {
                   currNodePtr->setNext(newNodePtr);
                   tail = newNodePtr;
              } 
              else if(currNodePtr == head)       //add to front
              {
                   newNodePtr->setNext(currNodePtr);
                   head = newNodePtr;
              }
              else                               //add in middle
              {
                   prevNodePtr->setNext(newNodePtr);
                   newNodePtr->setNext(currNodePtr);
              }
         }
         count++;
    }
    
    int listController::getCount()
    {
         return count;
    }
    
    void listController::printList()
    {
         class node *currNodePtr = NULL;
         
         currNodePtr = head;
         
         while(currNodePtr != NULL)
         {
              cout<<currNodePtr->getData()<<endl;
              currNodePtr->setNext(currNodePtr);
         }       
    }
    
    node * listController::deleteNode(int value)
    {
         class node *currNodePtr = NULL;
         class node *prevNodePtr = NULL;
         
         currNodePtr = head;
         prevNodePtr = head;
                                                 //loop until value is found
         while(currNodePtr != NULL && currNodePtr->getData() != value)
         {
              prevNodePtr = currNodePtr;
              currNodePtr = currNodePtr->getNext();
         }
         
         if(currNodePtr->getData() == value)
         {
              if(currNodePtr == head)            //if value found is first node
              {
                   head = currNodePtr->getNext();
              }
              else if(currNodePtr == tail)       //if value found is last node
              {
                   tail = prevNodePtr;
                   prevNodePtr->setNext(NULL);
              }
              else                               //if value found is somewhere in between
              {
                   prevNodePtr->setNext(currNodePtr->getNext());
              }
              
              count--;
         }    
         
         return currNodePtr;     
    } 
    
    int listController::deleteAllSpecific(int value)
    {
         class node *currNodePtr = NULL;
         class node *prevNodePtr = NULL;
         class node *tempNodePtr = NULL;
         
         int nodesDeleted = 0;
         
         currNodePtr = head;
         prevNodePtr = head;
                                                      //loop until null
         while(currNodePtr != NULL)
         {
              if(currNodePtr->getData() == value)
              {
                   if(currNodePtr == head)            //if value found is first node
                   {
                        head = currNodePtr->getNext();
                        prevNodePtr = currNodePtr->getNext();
                   }
                   else if(currNodePtr == tail)       //if value found is last node
                   {
                        tail = prevNodePtr;
                        prevNodePtr->setNext(NULL);
                   }
                   else                               //if value found is somewhere in between
                   {
                        prevNodePtr->setNext(currNodePtr->getNext());
                   }
                   
                   nodesDeleted++;
                   count--;               
                   tempNodePtr = currNodePtr;               
                   currNodePtr = currNodePtr->getNext();                
    
                   delete(tempNodePtr);          //free node memory           
              }
              else                               //advance pointers
              {
                   prevNodePtr = currNodePtr;
                   currNodePtr = currNodePtr->getNext();
              }
         }
         
         return nodesDeleted;
    }
    
    int listController::deleteAll()
    {
         class node *currNodePtr = NULL;
         class node *tempNodePtr = NULL;
         
         int nodesDeleted = 0;
         
         currNodePtr = head;
         
         while(currNodePtr != NULL)
         {          
              tempNodePtr = currNodePtr;
              currNodePtr = currNodePtr->getNext(); 
              head = currNodePtr;
              
              if(currNodePtr == NULL)
              {
                   tail = head;
              }
              
              nodesDeleted++;          
              count--;
              
              delete(tempNodePtr);     
         }
         
         return nodesDeleted;     
    }
    
    node * listController::searchList(int value)
    {     
         class node *currNodePtr = NULL;
         
         currNodePtr = head;
         
         while(currNodePtr != NULL && currNodePtr->getData() != value)
         {
              currNodePtr = currNodePtr->getNext();
         }
         
         return currNodePtr;     
    }
    
    int listController::isEmpty()
    {
         int flag = 1;
         
         if(count > 0)
         {
              flag = 0;
         }
         
         return flag;
    }
    //*********END OF CLASS LISTCONTROLLER*********//
    
    
    
    //***********************MAIN******************//
    int main()
    {    
    
         //professors code here
         
         system("PAUSE");
         return(0);    
         
         
    }
    //*****************END OF MAIN*****************//

  6. #6
    User
    Join Date
    Jan 2006
    Location
    Canada
    Posts
    499
    I don't want to sound goody-goody, but you're not supposed to put URGENT and PLEASE HELP NOW on your posts––it will not make people look any faster.

    http://cboard.cprogramming.com/annou...ouncementid=51

  7. #7
    Registered User
    Join Date
    Mar 2005
    Posts
    18
    Quote Originally Posted by joeprogrammer
    I don't want to sound goody-goody, but you're not supposed to put URGENT and PLEASE HELP NOW on your posts––it will not make people look any faster.

    http://cboard.cprogramming.com/annou...ouncementid=51


    Ok, didn't see that in the rules. My mistake. That sounds like a flame to me j/k - Anyone feel free to change the title.

  8. #8
    Registered User
    Join Date
    Mar 2005
    Posts
    18
    OK. I edited this post. I got the code to run and it works. I have a question about the Copy Constructor and Destructor. If I pull them out of the program it still works fine. Why??? I didn't think it would work or at least the links would be messed up. Any thoughts? Thanks again.


    Code:
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    //******************CLASS NODE*****************// 
    class node
    {
         private:
              int data;
              node *next;
         public:
              node(int);
              node *getNext();
              void setNext(node *);
              void setData(int);
              int getData();
    
    };
    
    
    node::node(int value)
    {
         data = value;
         next = '\0';     
    }
    
    node * node::getNext()
    {
         return next;
    }
    
    void node::setNext(node *newNodePtr)
    {
        next = newNodePtr;     
    }
    
    void node::setData(int value)
    {
         data = value;
    }
    
    int node::getData()
    {
         return data;
    } 
    //***********END OF CLASS NODE*****************//
    
    
    //************CLASS LISTCONTROLLER*************//
    
    class listController
    {
         private:
              int count;
              node *head;
              node *tail;
         public:
              listController();
              listController(const listController &);
              ~listController();
              void add(node *);
              int getCount();
              void printList();
              node *deleteNode(int);
              int deleteAllSpecific(int);
              int deleteAll();
              node *searchList(int);
              int isEmpty();
    };
    
    
    listController::listController()
    {
         count = 0;
         head = '\0';
         tail = '\0';
    }
    
    listController::listController(const listController &Copy)
    {
         node *origCurrNodePtr = NULL;                //pointer to original linked list
         node *copyCurrNodePtr = NULL;                //pointer to copied linked list
         
         origCurrNodePtr = Copy.head;                 //set orig pointer to head
         head = new node(*(Copy.head));               //create first copy node w/head pointing to it          
         copyCurrNodePtr = head;                      //set copy pointer to head   
         
         while(origCurrNodePtr->getNext() != NULL)    //loop through orig link and make a copy
         {
              origCurrNodePtr = origCurrNodePtr->getNext();                    //advance orig pointer
              copyCurrNodePtr->setNext(new node(origCurrNodePtr->getData()));  //make new node to copy ptr
              copyCurrNodePtr = copyCurrNodePtr->getNext();                    //advance copy ptr
              
         }    
              
         tail = copyCurrNodePtr;                      //set tail to last node
         count = Copy.count;                          //copy count
    }
    
    listController::~listController()
    {
         node *currNodePtr = NULL;
         node *tempNodePtr = NULL;
       
         currNodePtr = head;
         
         while(currNodePtr != NULL)
         {          
              tempNodePtr = currNodePtr;
              currNodePtr = currNodePtr->getNext(); 
              head = currNodePtr;
              
              if(currNodePtr == NULL)
              {
                   tail = head;
              }
              
              delete(tempNodePtr);     
         }
         
    }
    
    void listController::add(node *newNodePtr)
    {     
         node *currNodePtr = NULL;
         node *prevNodePtr = NULL;
         
         currNodePtr = head;
         prevNodePtr = head;      
         
         if(head == NULL)                        //no nodes (first node to add)
         {
              head = newNodePtr;
              tail = newNodePtr;
         }          
         else
         {
              while(currNodePtr != NULL && currNodePtr->getData() >= newNodePtr->getData())
              {   
                   prevNodePtr = currNodePtr;
                   currNodePtr = currNodePtr->getNext();
              }               
              if(currNodePtr == NULL)            //add to rear
              {
                   prevNodePtr->setNext(newNodePtr);
                   tail = newNodePtr;
              } 
              else if(currNodePtr == head)       //add to front
              {
                   newNodePtr->setNext(currNodePtr);
                   head = newNodePtr;
              }
              else                               //add in middle
              {
                   prevNodePtr->setNext(newNodePtr);
                   newNodePtr->setNext(currNodePtr);
              }
         }
         count++;
    }
    
    int listController::getCount()
    {
         return count;
    }
    
    void listController::printList()
    {
         node *currNodePtr = NULL;
         
         currNodePtr = head;
         
         while(currNodePtr != NULL)
         {
              cout<<currNodePtr->getData()<<endl;
              currNodePtr = currNodePtr->getNext();
         }       
    }
    
    node * listController::deleteNode(int value)
    {
         node *currNodePtr = NULL;
         node *prevNodePtr = NULL;
         
         currNodePtr = head;
         prevNodePtr = head;
                                                 //loop until value is found
         while(currNodePtr != NULL && currNodePtr->getData() != value)
         {
              prevNodePtr = currNodePtr;
              currNodePtr = currNodePtr->getNext();
         }
         
         if(currNodePtr->getData() == value)
         {
              if(currNodePtr == head)            //if value found is first node
              {
                   head = currNodePtr->getNext();
              }
              else if(currNodePtr == tail)       //if value found is last node
              {
                   tail = prevNodePtr;
                   prevNodePtr->setNext(NULL);
              }
              else                               //if value found is somewhere in between
              {
                   prevNodePtr->setNext(currNodePtr->getNext());
              }
              
              count--;
         }    
         
         return currNodePtr;     
    } 
    
    int listController::deleteAllSpecific(int value)
    {
         node *currNodePtr = NULL;
         node *prevNodePtr = NULL;
         node *tempNodePtr = NULL;
         
         int nodesDeleted = 0;
         
         currNodePtr = head;
         prevNodePtr = head;
                                                      //loop until null
         while(currNodePtr != NULL)
         {
              if(currNodePtr->getData() == value)
              {
                   if(currNodePtr == head)            //if value found is first node
                   {
                        head = currNodePtr->getNext();
                        prevNodePtr = currNodePtr->getNext();
                   }
                   else if(currNodePtr == tail)       //if value found is last node
                   {
                        tail = prevNodePtr;
                        prevNodePtr->setNext(NULL);
                   }
                   else                               //if value found is somewhere in between
                   {
                        prevNodePtr->setNext(currNodePtr->getNext());
                   }
                   
                   nodesDeleted++;
                   count--;               
                   tempNodePtr = currNodePtr;               
                   currNodePtr = currNodePtr->getNext();                
    
                   delete(tempNodePtr);          //free node memory           
              }
              else                               //advance pointers
              {
                   prevNodePtr = currNodePtr;
                   currNodePtr = currNodePtr->getNext();
              }
         }
         
         return nodesDeleted;
    }
    
    int listController::deleteAll()
    {
         node *currNodePtr = NULL;
         node *tempNodePtr = NULL;
         
         int nodesDeleted = 0;
         
         currNodePtr = head;
         
         while(currNodePtr != NULL)
         {          
              tempNodePtr = currNodePtr;
              currNodePtr = currNodePtr->getNext(); 
              head = currNodePtr;
              
              if(currNodePtr == NULL)
              {
                   tail = head;
              }
              
              nodesDeleted++;          
              count--;
              
              delete(tempNodePtr);     
         }
         
         return nodesDeleted;     
    }
    
    node * listController::searchList(int value)
    {     
         node *currNodePtr = NULL;
         
         currNodePtr = head;
         
         while(currNodePtr != NULL && currNodePtr->getData() != value)
         {
              currNodePtr = currNodePtr->getNext();
         }
         
         return currNodePtr;     
    }
    
    int listController::isEmpty()
    {
         int flag = 1;
         
         if(count > 0)
         {
              flag = 0;
         }
         
         return flag;
    }
    //*********END OF CLASS LISTCONTROLLER*********//
    
    
    //******************MAIN FUNCTIONS**********************//
    node *makeNode(int value)
    {
         node *newNodePtr = '\0'; 
       
         newNodePtr = new node(value);
         
         return newNodePtr;
    }
    //*************END OF MAIN FUNCTIONS********************//
    
    
    //***********************MAIN******************//
    int main()
    {     
         int number = 0;
         int nodes = 0;
         node *result;
         char selection;      
         char inputArray[256];
         char numberArray[256];
         
         listController L1; 
         
         do
         {  
              cout<<endl<<
              "-->[A] or [a] will add a node"<<endl<<
              "-->[D] or [d] will delete a specific node"<<endl<<     
              "-->[E] or [e] will exit the program"<<endl<<     
              "-->[L] or [l] will search for a specific node"<<endl<<
              "-->[M] or [m] will delete all nodes in list"<<endl<<
              "-->[P] or [p] will print the list"<<endl<<          
              "-->[S] or [s] will delete all nodes with same value"<<endl<<endl;                  
              
              cout<<"Enter a command---> ";
              fgets(inputArray,256,stdin);
         
              selection = inputArray[0];
              number = atoi(&inputArray[1]);
    
              switch(toupper(selection))
              {
                   case 'A':                //add a node
                        L1.add(makeNode(number));  
                        cout<<endl<<"Node Count: "<<L1.getCount()<<endl<<endl;                  
                        break;
                   case 'D':                //delete a specific node
                        if(L1.getCount() == 0)
                        {
                             cout<<endl<<"There are no nodes left to delete"<<endl<<endl;
                        }
                        else
                        {
                             result = L1.deleteNode(number);
                             cout<<endl<<"Node Count: "<<L1.getCount()<<endl<<endl;
                             cout<<"Return: "<<result<<endl;
                        }
                        break;
                   case 'E':                //will exit the program
                        printf("\n\n\n");                   
                        break; 
                   case 'L':                //will search for a specific node
                        if(L1.getCount() == 0)
                        {
                             cout<<endl<<"There are no nodes left to search"<<endl<<endl;
                        }
                        else
                        {
                             result = L1.searchList(number);
                             cout<<endl<<"Node Count: "<<L1.getCount()<<endl<<endl;
                             cout<<"Return: "<<result<<endl;
                        } 
                        break;
                   case 'M':                //delete all nodes in list
                        if(L1.getCount() == 0)
                        {
                             cout<<endl<<"There are no nodes left to delete"<<endl<<endl;
                        }
                        else
                        {
                             nodes = L1.deleteAll();
                             cout<<endl<<"Node Count: "<<L1.getCount()<<endl<<endl;
                             cout<<"Nodes deleted: "<<nodes<<endl;
                        }
                        break; 
                   case 'P':                //will print the list
                        if(L1.getCount() == 0)
                        {
                             cout<<endl<<"There are no nodes to print"<<endl<<endl;
                        }
                        else
                        {
                             L1.printList();
                             cout<<endl<<"Node Count: "<<L1.getCount()<<endl<<endl;
                        }                     
                        break;                                                            
                   case 'S':                //delete all nodes with same value
                        if(L1.getCount() == 0)
                        {
                             cout<<endl<<"There are no nodes left to delete"<<endl<<endl;
                        }
                        else
                        {
                             nodes = L1.deleteAllSpecific(number);
                             cout<<endl<<"Node Count: "<<L1.getCount()<<endl<<endl;
                             cout<<"Return: "<<nodes<<endl;
                        }                        
                        break;
                   default:
                        printf("\n\n*****You have entered an invalid command*****\n\n\n");
              }
              
         }while(selection != 'e' && selection != 'E');  
           
    
         system("PAUSE");
         
         return 0;
         
         
    }
    //*****************END OF MAIN*****************//
    Last edited by pityocamptes; 05-03-2006 at 02:16 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. single linked list to double linked list (help)
    By Countfog in forum C Programming
    Replies: 8
    Last Post: 04-29-2008, 08:04 PM
  2. Linked List Class with Pointers to Objects and using Polymorphism
    By CaptainMorgan in forum C++ Programming
    Replies: 3
    Last Post: 11-20-2006, 11:41 AM
  3. Reverse function for linked list
    By Brigs76 in forum C++ Programming
    Replies: 1
    Last Post: 10-25-2006, 10:01 AM
  4. Template Class for Linked List
    By pecymanski in forum C++ Programming
    Replies: 2
    Last Post: 12-04-2001, 09:07 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM