0% found this document useful (0 votes)
30 views4 pages

DS Lab 10 (2020-BSE-051)

Uploaded by

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

DS Lab 10 (2020-BSE-051)

Uploaded by

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

Department of Software Engineering

Data Structures & Algorithms Lab


Lab # 10

SUBMITTED TO:
Sir Rehan Ahmed Siddiqui
SUBMITTED BY:
Mahnoor Mustafa
(2020-BSE-051)
CLASS:
BSE III B
Code task 1:
#include <iostream>
using namespace std;
class CList
{
private:
struct node
{
int data;
node* next;
node* pre;
} *head;
public:
CList()
{
head = NULL;
}
bool emptyList() {
if (head == NULL)
return true;
else
return false;
}
void insert(int pos, int value)
{
node* temp;
temp = new node;
temp->data = value;
node* search;
search = head;
for (int count = 1; count < pos; count++)
{
search = search->next;
}
search->next->pre = temp;
temp->next = search->next;
search->next = temp;
temp->pre = search;
}
void insert_begin(int value)
{
node* temp;
temp = new node;
temp->data = value;
if (emptyList())
{
temp->next = temp;
temp->pre = temp;
head = temp;
}
else
{
node* search;
search = head;
while (search->next != head)
{
search = search->next;
}
temp->next = head;
temp->pre = search;
search->next = temp;
head->pre = temp;
head = temp;
}
}
void insert_end(int value)
{
node* temp;
temp = new node;
temp->data = value;
if (emptyList())
{
temp->next = temp;
temp->pre = temp;
head = temp;
}
else
{
head->pre->next = temp;
temp->pre = head->pre;
head->pre = temp;
temp->next = head;
}
}
void delete_begin()
{
node* search, * del;
search = head;
del = head;
while (search->next != head)
{
search = search->next;
}
head->next->pre = search;
search->next = head->next;
head = search->next;
delete del;
}
void delete_end()
{
node* search, * search2;
search = head;
search2 = head->next;
while (search2->next != head)
{
search = search->next;
search2 = search2->next;
}
search->next = head;
head->pre = search;
delete search2;
}
void traverse()
{
node* s;
s = head;
do
{
cout << s->data << "->";
s = s->next;
} while (s != head);
}
void traverse2()
{
node* s;
s = head->pre;
do
{
cout << s->data << "-> ";
s = s->pre;
} while (s != head->pre);
}
};
int main()
{
CList c1;
c1.insert_begin(4);
c1.insert_begin(6);
c1.insert_begin(8);
c1.insert_end(2);
c1.insert_end(0);
c1.insert(3, 3);
cout << "\nNodes \n";
c1.traverse();
cout << "\nReverse Order \n";
c1.traverse2();
cout << "\nNodes after Delete begin \n";
c1.delete_begin();
c1.traverse();
cout << "\nNodes after Delete end \n";
c1.delete_end();
c1.traverse();
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy