Question: / / singly _ linked _ list.cpp : Defines the entry point for the console application. / / #include stdafx.h #include #include using namespace

// singly_linked_list.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include
#include
using namespace std;
struct Node
{
int data;
string x;
Node* next; //it will contain pointer to the next node in the list.
};
class LinkedList
{
private:
Node* head; //pointing to the first node in the list
public:
LinkedList()
{
head=nullptr;
}
void insert(int data, string b)
{
Node* new_node = new Node();
new_node->data = data;
new_node->x = b;
new_node->next = nullptr;
if(head==nullptr)
{
head = new_node;
}
else
{
Node* temp = head;
while(temp->next!=nullptr)
{
temp = temp->next;
}
temp->next = new_node; //this points to last current node in list
}
}
void display()
{
Node* temp = head;
while(temp!=nullptr)
{
coutdata==value)
{
head = temp->next;
delete temp; //to free the memory
}
while(temp!=nullptr && temp->data!=value)
{
prev = temp;
temp = temp->next;
}
if(temp==nullptr)//if list is empty
{
cout<<"Item is not in the list";
return;
}
prev->next = temp->next;
delete temp;
}
};
int main(){
LinkedList l;
l.insert(10, "Ahmed");
l.insert(20, "Habib");
l.insert(30, "Ali");
l.insert(40, "Moeen");
l.insert(50, "sohaib");
l.insert(60, "Abdul Rafeh");
cout<<"Below is the inserted list of Items : ";
l.display();
cout<
You have to implement the search data and update data function in the sample singly linked list source code.
2. Implement the complete doubly linked list, implement the insert node, delete node, update node data, search data, display data from doubly linked list.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!