Linked List Using C++

    

 

 Below we will discuss about different functions of linked list implementation.

 

/* 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;

};

Whenever we write a class, it begins with the word class followed by the class-name and the body of the class enclosed within curly braces. In the body, we write its public variables, methods and then private variables and methods, this is normally the sequence.

If there is no code to write inside the constructor function of a class, we need not to declare it ourselves as the compiler automatically creates a default constructor for us. Similarly, if there is nothing to be done by the destructor of the class, it will be better not to write it explicitly. Rather, the compiler writes it automatically. Remember, the default constructor and destructor do nothing as these are the function without any code statements inside.

 

BACK

HOME

NEXT