0% found this document useful (0 votes)
31 views5 pages

Linked List Implementation

The document discusses the implementation of linked lists in C++. It describes traversing a linked list by storing node information and links in arrays and using a starting pointer to iterate through each node. It also provides code to insert a new node at the beginning of the list by assigning the new node's link to the original start and updating start to point to the new node.

Uploaded by

MAYA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views5 pages

Linked List Implementation

The document discusses the implementation of linked lists in C++. It describes traversing a linked list by storing node information and links in arrays and using a starting pointer to iterate through each node. It also provides code to insert a new node at the beginning of the list by assigning the new node's link to the original start and updating start to point to the new node.

Uploaded by

MAYA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

LINKED LISTS IMPLEMENTATION IN C++

TRAVERSING IN LINKED LIST


It uses array to store info part and link part in implementation so it starts from 0 to
N-1 terms. Input can also be given at Run time then there you can have array
length from 1 to N terms. -1 (negative number shows null pointer).

Linked Lists to be Implemented in Traversing:

INFO

LINK

START

LINKED LISTS IMPLEMENTATION

MARIA SHAIKH

IMPLEMENTATION OF TRAVERSING:
#include<iostream>
using namespace std;
int main()
{
char info[9]={'a','b','c','d','e','f','g','h','i'};

int link[9]={8,7,0,6,1,2,-1,3,4};

int start=5;
int ptr=start;
while (ptr!=-1)
{
cout<<info[ptr]<<'\t';
ptr=link[ptr];

}
return 0;
}

LINKED LISTS IMPLEMENTATION

MARIA SHAIKH

Implementation of Inserting a node at the beginning of the


list:
#include<iostream>
using namespace std;
const int size=10;
int main()
{
int info[size]={1,0,0,4,0,6,0,0,0,0};
int link[size]={-1,4,1,0,6,3,7,8,9,-1};
int start=5,avail=2;
int item,ptr,newnode;
cout<<"list is \t";
ptr=start;
LINKED LISTS IMPLEMENTATION

MARIA SHAIKH

while(ptr!=-1)
{
cout<<info[ptr]<<"\t";
ptr=link[ptr];
}
cout<<"\n Enter element you want to insert in the list:";
cin>>item;
if(avail==-1)
{
cout<<"overflow";
}
else
{
newnode=avail;
avail=link[avail];

}
info[newnode]=item;
link[newnode]=start;
start=newnode;
cout<<"list after insertion is \t";
ptr=start;
while (ptr!=-1)
{
cout<<info[ptr]<<"\t";
LINKED LISTS IMPLEMENTATION

MARIA SHAIKH

ptr=link[ptr];
}
return 0;

LINKED LISTS IMPLEMENTATION

MARIA SHAIKH

You might also like