+92 332 4229 857 99ProjectIdeas@Gmail.com

Linked Lists (C++)


Linked Lists
Linked list is a data structure which consists of different nodes connected with each other through a pointer.
Node consists of 2 parts:
First part is the data part and the second part is the reference part which points to the next node.
Linked lists are used to implement other data structures like stacks, queues, arrays etc.

Structure definition for node
struct Node
{
public:
       int data;
       Node*next;
      
       Node();
};

Structure implementation for node
Node::Node()
{
       data=0;
       next=NULL;
}

Class definition for linked list
class LinkList
{
public:
       Node*head;
       LinkList();
};

Class implementation for linked list
LinkList::LinkList()
{
       head=NULL;
}

How to insert a new node to the end of linked list
For inserting a new node to the end of the linked list, read:

How to insert a new node to the start of linked list
For inserting a new node to the start of the linked list, read:

0 comments: