SlideShare a Scribd company logo
Comsats University Islamabad
Sahiwal Campus
Date:
12/03/2019
Instructor: Sir Mr M Ahmad Assignment: Data Structure
Prepared: Asjad Ali R Reg#: FA18-MCS-0552
#include<iostream>
using namespace std;
void mainmenu();
struct node
{
int data;
struct node *next;
struct node *previous;
};
struct node *head, *tmp, *p, *ptr;
class linklist
{
private:
int i;
public:
void add_first_node()
{
head = new node;
cout << "Enter the value of first this node : ";
cin >> head->data;
head->previous = NULL;
head->next = NULL;
}
void add_node(int a)
{
p = head;
i = 0;
do
{
if (a == p->data)
{
i++;
ptr = new node;
cout << "Enter the value of node n";
cin >> ptr->data;
ptr->next = p->next;
p->next = ptr;
ptr->previous = p;
tmp = ptr->next;
tmp->previous = ptr;
}
p = p->next;
} while (p->next != NULL);
if (i == 0)
{
Instructor: Sir Mr M Ahmad Assignment: Data Structure
Prepared: Asjad Ali R Reg#: FA18-MCS-0553
cout << a << " dose not exist in link list n";
}
}
void find_node_num(int a)
{
i = 1;
for (p = head; p != NULL; p = p->next)
{
if (p->data == a)
{
cout << " Node = " << i << " And Value =" <<
p->data << endl;
i++;
}
}
if (i == 1)
cout << a << " does not Exist in link list n";
}
void add_last()
{
p = head;
if (head == NULL)
cout << "link list dose not exist n";
else
{
p = head;
while (p->next != NULL)
p = p->next;
ptr = new node;
cout << "Enter the new node value :";
cin >> ptr->data;
p->next = ptr;
ptr->previous = p;
ptr->next = NULL;
}
}
void dalet_node()
{
p = head;
i = 0;
do
{
if (p->data > 50)
{
if (p == head)
{
head = head->next;
Instructor: Sir Mr M Ahmad Assignment: Data Structure
Prepared: Asjad Ali R Reg#: FA18-MCS-0554
i++;
}
else
{
i++;
ptr = p->next;
p = p->previous;
p->next = ptr;
ptr->previous = p;
}
}
p = p->next;
} while (p->next != NULL);
if (i == 0)
{
cout << "values in link list do not greater
than 50n";
}
}
void display()
{
p = head;
i = 1;
cout << "t Show ALL data in link listn ";
while (p != NULL)
{
cout << i << " Node value = " << p->data << endl;
p = p->next;
i++;
}
}
};
void mainmenu()
{
int choice, T;
linklist n;
cout << "nt==>>MENU<<==n";
cout << "1 for Add node FIRST if data not EXISTn";
cout << "2 for add nod in last in link listn";
cout << "3 for Add node after SPECIFIC data n";
cout << "4 for DELETE node when data GREATER than 50
n";
cout << "5 for FIND node number where data is
REAPETED
or SAME n";
cout << "6 for DISPLAY all data in link list n";
Instructor: Sir Mr M Ahmad Assignment: Data Structure
Prepared: Asjad Ali R Reg#: FA18-MCS-0555
cout << "7 for EXIT the programme n";
cin >> choice;
switch (choice)
{
case 1:
{
n.add_first_node();
mainmenu();
break;
}
case 2:
{
n.add_last();
mainmenu();
break;
}
case 3:
{
cout << "Enter the number after add
node n";
cin >> T;
n.add_node(T);
mainmenu();
break;
}
case 4:
{
n.dalet_node();
mainmenu();
break;
}
case 5:
{
cout << "Enter the number check
repteated : ";
cin >> T;
n.find_node_num(T);
Instructor: Sir Mr M Ahmad Assignment: Data Structure
Prepared: Asjad Ali R Reg#: FA18-MCS-0556
mainmenu();
break;
}
case 6:
{
n.display();
mainmenu();
break;
}
case 7:
{
exit(0);
break;
}
default:
{
cout << "Invalid input n";
mainmenu();
break;
}
}
}
int main()
{
mainmenu();
return 0;
}

More Related Content

PDF
201801 CSE240 Lecture 11
DOCX
contoh Program queue
DOCX
Write a program that calculate the no of prime no,even and odd no.
DOCX
Array using recursion
PDF
Program in ‘C’ language to implement linear search using pointers
PPTX
Operators and expression in c#
PDF
Data Visualization — Le funzionalità matematiche di Sage per la visualizzazio...
DOCX
Doubly linklist
201801 CSE240 Lecture 11
contoh Program queue
Write a program that calculate the no of prime no,even and odd no.
Array using recursion
Program in ‘C’ language to implement linear search using pointers
Operators and expression in c#
Data Visualization — Le funzionalità matematiche di Sage per la visualizzazio...
Doubly linklist

What's hot (20)

PDF
Linear search
DOCX
A Shiny Example-- R
PDF
Linked list searching deleting inserting
PDF
Insertion sort
DOCX
2 a networkflow
DOCX
PPTX
Session06 functions
TXT
Bankers Algo Implementation
DOCX
PROGRAM FOR INSERTION SORTING IN ARRAY
PDF
DOCX
Write a program to perform translation.
TXT
Program to sort array using insertion sort
PDF
Hexagonal architecture & Elixir
DOCX
Write a program to perform translation
DOCX
Experement no 6
DOCX
cosc 281 hw2
DOCX
Conversion from infix to prefix using stack
Linear search
A Shiny Example-- R
Linked list searching deleting inserting
Insertion sort
2 a networkflow
Session06 functions
Bankers Algo Implementation
PROGRAM FOR INSERTION SORTING IN ARRAY
Write a program to perform translation.
Program to sort array using insertion sort
Hexagonal architecture & Elixir
Write a program to perform translation
Experement no 6
cosc 281 hw2
Conversion from infix to prefix using stack
Ad

Similar to double link list in data structure (20)

PPTX
Singly linked list program in data structure - Vtech
DOCX
C++ adt c++ implementations
PPTX
C Assignment Help
PDF
Data Structure in C++Doubly Linked Lists of ints httpstaffwww.pdf
PDF
TutorialII_Updated____niceupdateprogram.pdf
DOCX
Bubble in link list
PDF
Please teach me how to fix the errors and where should be modified. .pdf
DOCX
Ahad Butt
TXT
pROgRAN C++ ApLiKaSI Binery tree
DOCX
Implement of c &amp; its coding programming by sarmad baloch
PDF
C++ Program to Implement Singly Linked List #includei.pdf
PPTX
Data Structures and Agorithm: DS 04 Linked List.pptx
PDF
C++ Program to Implement Singly Linked List #includeiostream.pdf
DOCX
Lab Week 2 Game Programming.docx
PDF
How to delete one specific node in linked list in CThanksSolu.pdf
DOCX
Solutionsfor co2 C Programs for data structures
DOCX
EXP_2_stck implementation using linked list Code.docx
PDF
#includeiostream struct node {    char value;    struct no.pdf
PPTX
Singly linked list.pptx
PDF
Program of sorting using shell sort #include stdio.h #de.pdf
Singly linked list program in data structure - Vtech
C++ adt c++ implementations
C Assignment Help
Data Structure in C++Doubly Linked Lists of ints httpstaffwww.pdf
TutorialII_Updated____niceupdateprogram.pdf
Bubble in link list
Please teach me how to fix the errors and where should be modified. .pdf
Ahad Butt
pROgRAN C++ ApLiKaSI Binery tree
Implement of c &amp; its coding programming by sarmad baloch
C++ Program to Implement Singly Linked List #includei.pdf
Data Structures and Agorithm: DS 04 Linked List.pptx
C++ Program to Implement Singly Linked List #includeiostream.pdf
Lab Week 2 Game Programming.docx
How to delete one specific node in linked list in CThanksSolu.pdf
Solutionsfor co2 C Programs for data structures
EXP_2_stck implementation using linked list Code.docx
#includeiostream struct node {    char value;    struct no.pdf
Singly linked list.pptx
Program of sorting using shell sort #include stdio.h #de.pdf
Ad

Recently uploaded (20)

PPTX
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
PDF
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
PDF
LDMMIA Reiki Yoga Finals Review Spring Summer
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
Hazard Identification & Risk Assessment .pdf
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
PDF
SOIL: Factor, Horizon, Process, Classification, Degradation, Conservation
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
Practical Manual AGRO-233 Principles and Practices of Natural Farming
PPTX
History, Philosophy and sociology of education (1).pptx
PDF
IGGE1 Understanding the Self1234567891011
PDF
Classroom Observation Tools for Teachers
PDF
Computing-Curriculum for Schools in Ghana
PDF
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PPTX
Lesson notes of climatology university.
PDF
RMMM.pdf make it easy to upload and study
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
LDMMIA Reiki Yoga Finals Review Spring Summer
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Hazard Identification & Risk Assessment .pdf
A powerpoint presentation on the Revised K-10 Science Shaping Paper
SOIL: Factor, Horizon, Process, Classification, Degradation, Conservation
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
Practical Manual AGRO-233 Principles and Practices of Natural Farming
History, Philosophy and sociology of education (1).pptx
IGGE1 Understanding the Self1234567891011
Classroom Observation Tools for Teachers
Computing-Curriculum for Schools in Ghana
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
Chinmaya Tiranga quiz Grand Finale.pdf
Lesson notes of climatology university.
RMMM.pdf make it easy to upload and study
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx

double link list in data structure

  • 1. Comsats University Islamabad Sahiwal Campus Date: 12/03/2019
  • 2. Instructor: Sir Mr M Ahmad Assignment: Data Structure Prepared: Asjad Ali R Reg#: FA18-MCS-0552 #include<iostream> using namespace std; void mainmenu(); struct node { int data; struct node *next; struct node *previous; }; struct node *head, *tmp, *p, *ptr; class linklist { private: int i; public: void add_first_node() { head = new node; cout << "Enter the value of first this node : "; cin >> head->data; head->previous = NULL; head->next = NULL; } void add_node(int a) { p = head; i = 0; do { if (a == p->data) { i++; ptr = new node; cout << "Enter the value of node n"; cin >> ptr->data; ptr->next = p->next; p->next = ptr; ptr->previous = p; tmp = ptr->next; tmp->previous = ptr; } p = p->next; } while (p->next != NULL); if (i == 0) {
  • 3. Instructor: Sir Mr M Ahmad Assignment: Data Structure Prepared: Asjad Ali R Reg#: FA18-MCS-0553 cout << a << " dose not exist in link list n"; } } void find_node_num(int a) { i = 1; for (p = head; p != NULL; p = p->next) { if (p->data == a) { cout << " Node = " << i << " And Value =" << p->data << endl; i++; } } if (i == 1) cout << a << " does not Exist in link list n"; } void add_last() { p = head; if (head == NULL) cout << "link list dose not exist n"; else { p = head; while (p->next != NULL) p = p->next; ptr = new node; cout << "Enter the new node value :"; cin >> ptr->data; p->next = ptr; ptr->previous = p; ptr->next = NULL; } } void dalet_node() { p = head; i = 0; do { if (p->data > 50) { if (p == head) { head = head->next;
  • 4. Instructor: Sir Mr M Ahmad Assignment: Data Structure Prepared: Asjad Ali R Reg#: FA18-MCS-0554 i++; } else { i++; ptr = p->next; p = p->previous; p->next = ptr; ptr->previous = p; } } p = p->next; } while (p->next != NULL); if (i == 0) { cout << "values in link list do not greater than 50n"; } } void display() { p = head; i = 1; cout << "t Show ALL data in link listn "; while (p != NULL) { cout << i << " Node value = " << p->data << endl; p = p->next; i++; } } }; void mainmenu() { int choice, T; linklist n; cout << "nt==>>MENU<<==n"; cout << "1 for Add node FIRST if data not EXISTn"; cout << "2 for add nod in last in link listn"; cout << "3 for Add node after SPECIFIC data n"; cout << "4 for DELETE node when data GREATER than 50 n"; cout << "5 for FIND node number where data is REAPETED or SAME n"; cout << "6 for DISPLAY all data in link list n";
  • 5. Instructor: Sir Mr M Ahmad Assignment: Data Structure Prepared: Asjad Ali R Reg#: FA18-MCS-0555 cout << "7 for EXIT the programme n"; cin >> choice; switch (choice) { case 1: { n.add_first_node(); mainmenu(); break; } case 2: { n.add_last(); mainmenu(); break; } case 3: { cout << "Enter the number after add node n"; cin >> T; n.add_node(T); mainmenu(); break; } case 4: { n.dalet_node(); mainmenu(); break; } case 5: { cout << "Enter the number check repteated : "; cin >> T; n.find_node_num(T);
  • 6. Instructor: Sir Mr M Ahmad Assignment: Data Structure Prepared: Asjad Ali R Reg#: FA18-MCS-0556 mainmenu(); break; } case 6: { n.display(); mainmenu(); break; } case 7: { exit(0); break; } default: { cout << "Invalid input n"; mainmenu(); break; } } } int main() { mainmenu(); return 0; }