Linked List Data Structure PDF
Linked List Data Structure PDF
What is Pointer?
Pointer contains memory address of a particular type of data.
In C++, we use * to declare a pointer.
2cdf 1a5c c75c
int p; int* iptr; char* cptr; p iptr 1a5c cptr c75c
cout<<*iptr; 9
cout<<emp.salary+1000.00; 41000.00
data
data
data
next
next
next
next
head 5 9 6 7 /
E.g2:
data
data
data
data
next
next
next
next
head
front 5 9 6 7 /
rear
1
HNDIT Data Structure and Algorithm SLIATE
E.g3:
previous
previous
previous
previous
data
data
data
data
next
next
next
next
head / 5 9 6 7 /
1. initializeList() head /
2. insertFirstElt(5)
data
next
head 5 /
3.insertAtFront(3)
data
next
head 5 /
data
next
newNode 3
4. insertAtEnd(8)
data
data
next
next
head 3 5
newNode 8 /
5. insertAfter(5,7)
data
data
data
next
next
next
head 3 5 8 /
newNode 7
2
HNDIT Data Structure and Algorithm SLIATE
6. deleteElt(5):
data
data
data
data
next
next
next
next
head 3 5 7 8 /
listNode* head;
public:
LinkedList();
void initializeList();
void insertFirstElt(int elt);
void insertAtFront(int elt);
void insertAtEnd(int elt);
void insertAfter(int oldElt, int newElt);
void deleteElt(int elt);
void displayList();
int isEmpty();
int isFull();
}
LinkedList::LinkedList() //Constructor
{
head=NULL;
}
void LinkedList::initializeList()
{
head=NULL;
}
3
HNDIT Data Structure and Algorithm SLIATE
newNode->next=head;
head=newNode;
}
void LinkedList::displayList()
{
listNode* curNode;
curNode=head;
while (curNode)
{
cout<<curNode->data<<" ";
curNode=curNode->next;
}
}
int LinkedList::isEmpty()
{
if (head== NULL)
return 1;
else
return 0;
}
4
HNDIT Data Structure and Algorithm SLIATE
{
return 0;
}
void main()
{
clrscr();
LinkedList lst;
lst.insertAtEnd(4);
lst.insertAtEnd(6);
lst.insertAtEnd(5);
lst.displayList();
}