Вы находитесь на странице: 1из 3

#ifndef _LINKEDLIST_H

#define _LINKEDLIST_H

#include <string>

struct Node
   {
   string agentName;
   int    caseNo;
    string caseDesc;
  
   Node * next;
  Node (const string& name, const int no , const string& desc, Node * nptr)
      : agentName(name),
        caseNo(no),
        caseDesc(desc),
        next(nptr)       
  {
     
  }
};

class LinkedList
{
 public:
   
   
   LinkedList();         // constructor
   ~LinkedList();        // destructor
   int  size()  const;              
   void addToStart(Node *) ;  
   void addToEnd(Node *) ;
   void printList() ;
   void removeNodeAt(int );
   
 
 private:

   Node * myHead;    // header node


   Node * myTail;    // last node in list, header if list is empty
   int    mySize;    // # nodes in linked list
};

#endif

#include "linkedlist.h"

LinkedList::LinkedList()
   : myHead(new Node("dummy",0,"dummy",0)),
     myTail(myHead),
     mySize(0)
// post: internal list is empty, one header node allocated
{
}

~LinkedList(){
  // write your code for releasing memory here...
}

// post: returns # nodes in list    


int LinkedList::size() const

{
   return mySize;
}

// add the new node at the start of list.


void LinkedList::addToStart(Node *n)
{    
   // Write your code here
   
   mySize++;    
}
// add the new node at the end of list.
void LinkedList::addToEnd(Node * n)
// pre: *n allocated
// post: *n is linked as last node of list, size increases by one        

{
 // Write your code here    mySize++;
}

// this function will print all nods in list.


void LinkedList::printList() {
    Node *temp = myHead->next ;
    cout<<" \n            values are \n"    ;
    while(temp)
    {
          cout<<"\n    Agent Name  : "<< temp->agentName;
          cout<<"\n    Case  No    : "<< temp->caseNo;
          cout<<"\n    Description : "<< temp->caseDesc;    
          cout << "\n\n\n ***********************************************************\n\n\n" ;   
          temp=temp->next;
     }
}

// remove the node at the given index


void LinkedList::removeNodeAt(int index){
    
    // Wtite your code here.
      
}
   

#include <iostream>
#include <stdlib.h>
#include <conio.h>
#include "linkedlist.h"
int main(int argc, char *argv[])
{
 LinkedList myList;
 Node *node  ;
 int choice = 0 , index=0 ;
 string agentName, caseDesc ;
 int caseNo;
 do
 {
     
     cout<< "\n Enter 1 Add a new node to the end \n";
     cout<< " Enter 2 Add a new node to the beginning \n";
     cout<< " Enter 3 Print out the entire list \n";
     cout<< " Enter 4 Remove a node from the list \n";
     cout<< " Enter 5 Quit the program \n";
     cout<< " Enter your choice : ";
     cin>> choice;
     switch(choice){
       case 1:
                   //  Insert appropriate code here ....
       break;
      
       case 2:
                   //  Insert appropriate code here ....
       break;
       
       case 3:
                   //  Insert appropriate code here ....
       break;
       
       case 4:
                   //  Insert appropriate code here ....        
       break;
       
       case 5:
         exit(1);
       break;      
       
       default :
         cout<<"\n   Invalid Option, Please try again .....\n";
       break;
     
     }
     
 }while (true);

Вам также может понравиться