Step 1: Create Class For Nodetype: Linked List Implementation - Mohsin Abbas
Step 1: Create Class For Nodetype: Linked List Implementation - Mohsin Abbas
Page 1 of 7
Linked List Implementation – Mohsin Abbas
Page 2 of 7
Linked List Implementation – Mohsin Abbas
Page 3 of 7
Linked List Implementation – Mohsin Abbas
#pragma once
#include "nodeType.h"
#include "linkedListType.h"
if (isEmptyList())
{
cout << "The list is empty" << endl;
}
else
{
trailCurrent = first;
current = first->link;
while (1)
{
if (current->info == deleteItem)
{
found = true;
break;
}
else
{
trailCurrent = current;
current = current->link;
}
}
if (found)
{
trailCurrent->link = current->link;
if (last == current)
last = trailCurrent;
delete current;
count--;
}
else
{
cout << "Item not found in the list" << endl;
}
}
}
Page 4 of 7
Linked List Implementation – Mohsin Abbas
if (temp->link == NULL)
{
if (temp->info == searchItem)
{
found = true;
break;
}
}
}
return found;
}
};
Page 5 of 7
Linked List Implementation – Mohsin Abbas
if (isEmptyList())
{
first = newNode;
last = newNode;
count++;
}
else if (count == 1)
{
if (newItem > first->info)
{
newNode->link = first;
first = newNode;
}
else
{
first->link = newNode;
}
count++;
}
else
{
if (newItem > first->info)
{
newNode->link = first;
first = newNode;
count++;
}
else
{
current = first->link;
trailCurrent = first;
while (1)
{
if (newItem > current->info)
found = true;
else
{
trailCurrent = trailCurrent->link;
current = current->link;
}
if (found||current==NULL)
{
newNode->link = current;
trailCurrent->link = newNode;
count++;
break;
}
}
}
}
}
Page 6 of 7
Linked List Implementation – Mohsin Abbas
Page 7 of 7