linked list : Your list « Data Types « C++ Tutorial






#include <iostream>  
  using namespace std;  
  
  struct link                       
    {  
     int data;                      
     link* next;                    
    };  
  
  class linklist                    
    {  
     private:  
        link* first;                
     public:  
        linklist(){ first = NULL; }        
        void additem(int d);          
        void display();             
    };  
  void linklist::additem(int d)        
    {  
     link* newlink = new link;         
     newlink->data = d;                
     newlink->next = first;            
     first = newlink;                    
    }  
  void linklist::display()             
    {  
     link* current = first;            
     while( current != NULL ){  
        cout << current->data << endl; 
        current = current->next;       
     }  
    }  
  
  int main()  
    {  
     linklist li;       
    
     li.additem(25);      
     li.additem(36);  
     li.additem(49);  
     li.additem(64);  
    
     li.display();      
     return 0;  
    }








2.38.Your list
2.38.1.List of integers
2.38.2.linked list
2.38.3.Manage list of employees based on STL
2.38.4.Implementation of a safe array type vect
2.38.5.Vector with raised exceptions