Example Program

    

 

Given below is the full source code of the example program. You can copy, past and compile it right away. In order to understand the linked list concept fully, it is highly desirable that you understand and practice with the below code.

#include  <iostream.h>

#include  <stdlib.h>

/* The Node class */

class   Node

{

public:

int   get() { return   object; };

void   set(int object) { this->object  =  object; };

Node *   getNext() { return   nextNode; };

void   setNext(Node * nextNode) { this->nextNode  =  nextNode; };

private:

int   object;

Node *   nextNode;

};

/* The List class */

class   List

{

public:

List();

void   add (int   addObject);

int   get();

bool   next();

friend   void   traverse(List   list);

friend   List   addNodes();

private:

int   size;

Node *   headNode;

Node *   currentNode;

Node *   lastCurrentNode;

};

 

BACK

HOME

NEXT