Linked List Insert Traverse Delete Implementation & Operations in Data Structures (C++)
In this tutorial, we will learn about Linked List Insert Traverse Delete Implementation & Operations in Data Structures (C++).
//C++ Code Snippet - Linked List Implementation using C++ Program
#include <iostream>
using namespace std;
//Declaration of Node
struct Node{
int number;
Node *next;
};
//Declaration of Head node
struct Node *head=NULL;
//Inserting node at start
void node_insertion(int a)
{
struct Node *newNode=new Node;
newNode->number=a;
newNode->next=head;
head=newNode;
}
//Traversing/displaying entered nodes
void show()
{
if(head==NULL)
{
cout<<" Linked List is empty!"<<endl;
return;
}
struct Node *temp=head;
while(temp!=NULL)
{
cout<<temp->number<<" ";
temp=temp->next;
}
cout<<endl;
}
//Deleting node from start
void del_Item()
{
if(head==NULL){
cout<<"Linked List is empty!"<<endl;
return;
}
cout<<head->number<<" is removed."<<endl;
head=head->next;
}
int main()
{
show();
node_insertion(15);
node_insertion(30);
node_insertion(45);
node_insertion(60);
node_insertion(75);
show();
del_Item(); del_Item(); del_Item(); del_Item(); del_Item();
del_Item();
show();
return 0;
}
Output:
