Link List Code
Link List Code
struct node
{
int data;
node* next;
};
//Node
Data Next
Create Nodes
node* n; n
t
node* t; //temp node
h
node* h; //head node
Point to Newly Created Node
n = new node;
n Data Next
n data = 1;
n 1 Next
Set Temporary Values
n
t = n; 1 Next
t
h = n; n
1 Next
t
h
Build a List
n = new node;
h
Build a List
n data = 2;
1 Next 2 Next
t
n
h
Build a List
t next = n;
t = t next;
t
1 Next 2 Next
n
h
n = new node;
n data =3;
t next =n;
n next = NULL;
t
1 Next 2 Next 3 NULL
n
h
Link List Class
//List.h
Class List
{
Private:
struct node
{
int data;
node* next;
};
Public:
List();
void AddNode(int addData);
void DeleteNode(int delData);
void PrintList();
}
List.cpp
//Constructor
List :: List()
{
head = NULL;
current = NULL;
temp = NULL;
}
//AddNode Function
delete delptr;
}
Print Function
int main()
{
List obj;
obj.AddNode(1);
obj.AddNode(2);
obj.AddNode(3);
obj.PrintList();
obj.DeleteNode(2);
obj.PrintList();
}