SlideShare a Scribd company logo
MILITARY COLLEGE OF SIGNALS, NUST
2015
data structure lab 03
to SIR HAMMAD
AMEER HAMZA
MUHAMMAD MUNEEB MALIK
bete 51 -C
R A W A L P I N D I , P A K I S T A N
Question NO. 1 all parts in one....
#include<iostream.h>
#include<conio.h>
struct node{
node *next;
int data;
};
class list{
private:
node *head,*temp,*temp1,*temp2,*temp3;
public:
list(){
head=NULL;
}
//----------------------------------------create---------------
void create(){
int y,u;
cin>>u;
for(int i=0;i<u;i++){
if(head==NULL){
temp=new node();
cout<<"enter the node valuet:";
cin>>y;
temp->data=y;
temp->next=NULL;
head=temp;
}
else{
temp=new node();
cout<<"enter the node valuet:";
cin>>y;
temp->data=y;
temp->next=NULL;
temp1=head;
while(temp1->next!=NULL){
temp1=temp1->next;
}
temp1->next=temp;
}
}
temp->next=head;
}
//--------------------------------------------display--------
void display(){
temp1=head;
int ai=0;
while(ai!=20){
cout<<temp1->data<<endl;
temp1=temp1->next;
ai++;
}
}
//-------------------------------------------traverse--------
void tra(){
int ty,con=0,tr=0;
temp2=head;
while(temp2->next!=head){
con++;
temp2=temp2->next;
}
temp2=head;
cout<<"enter the position to traverse fromt:";
cin>>ty;
for(int i=0;i<ty;i++){
temp2=temp2->next;
}
for(int i=0;i<=con;i++){
cout<<"traversedt:"<<temp2->data<<endl;
temp2=temp2->next;
}
}
//-------------------------------------------delete-----------
void del(){
int o,dat,q=0;
cout<<"enter the positiont:";
cin>>o;
if(o==1){
temp1=head;
temp3=head;
while(temp3->next!=head){
temp3=temp3->next;
}
head=head->next;
temp3->next=head;
delete temp1;
}
else{
temp2=head;
while(temp2->next!=head){
q++;
temp2=temp2->next;
}
if(o==q){
temp3=head;
while(temp3->next!=head){
temp2=temp3;
temp3=temp3->next;
}
temp2->next=head;
delete temp3;
}
else{
temp1=head;
temp2=temp1;
for(int i=0;i<o-1;i++){
temp2=temp1;
temp1=temp1->next;
}
temp3=temp1;
temp1=temp1->next;
temp2->next=temp1;
delete temp3;
}
}
}
//-------------------------------------------insert-----------
void insert(){
int c=1, e,da;
cout<<"enter the positiont:";
cin>>e;
temp1=head;
if(e==1){
temp=new node();
cout<<"enter the valuet:";
cin>>da;
temp->data=da;
temp3=head;
while(temp3->next!=head){
temp3=temp3->next;
}
temp->next=temp1;
head=temp;
temp3->next=head;
}
else{
temp2=head;
while(temp2->next!=head){
c++;
temp2=temp2->next;
}
if(e==c){
temp=new node();
cout<<"enter the valuet:";
cin>>da;
temp->data=da;
temp1=head;
while(temp1->next!=head){
temp1=temp1->next;
}
temp1->next=temp;
temp->next=head;
}
else{
temp=new node();
cout<<"enter the valuet:";
cin>>da;
temp->data=da;
temp1=head;
for(int i=0;i<e-1;i++){
temp2=temp1;
temp1=temp1->next;
}
temp2->next=temp;
temp->next=temp1;
}
}
}
};
int main(){
list a;
a.create();
a.insert();
a.display();
a.del();
a.display();
a.tra();
getch();
}
RESULT:
Data structure lab 03ameer hamza

More Related Content

PPT
Memoria Simulada
PDF
CM 1.3a MrG Functions, Domain, Range
DOCX
Programas de for y do
DOCX
TXT
Some logics
TXT
Numeros primos
TXT
Python codigo graficas
DOCX
Data Structure Project File
Memoria Simulada
CM 1.3a MrG Functions, Domain, Range
Programas de for y do
Some logics
Numeros primos
Python codigo graficas
Data Structure Project File

Viewers also liked (19)

PDF
Data Structures and Algorithms made Easy (Cover Page)
DOCX
Assignment
PDF
C program
DOCX
Data structure new lab manual
DOCX
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)
PDF
Data structures lab c programs
PDF
Data structures and algorithms made easy
DOCX
Data Structure in C (Lab Programs)
PDF
VTU 1ST SEM PROGRAMMING IN C & DATA STRUCTURES SOLVED PAPERS OF JUNE-2015 & ...
DOC
Datastructure notes
PDF
Lab manual of C++
PDF
C notes.pdf
PDF
Data structures lab manual
PPTX
Data structure and its types
PPT
Data structures
PDF
Relational Database Management System
PDF
Ds lab handouts
PPT
Lecture 1 data structures and algorithms
PPT
DATA STRUCTURES
Data Structures and Algorithms made Easy (Cover Page)
Assignment
C program
Data structure new lab manual
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)
Data structures lab c programs
Data structures and algorithms made easy
Data Structure in C (Lab Programs)
VTU 1ST SEM PROGRAMMING IN C & DATA STRUCTURES SOLVED PAPERS OF JUNE-2015 & ...
Datastructure notes
Lab manual of C++
C notes.pdf
Data structures lab manual
Data structure and its types
Data structures
Relational Database Management System
Ds lab handouts
Lecture 1 data structures and algorithms
DATA STRUCTURES
Ad

Recently uploaded (11)

PDF
واقع-تكوين-المعلمين-واحتياجاتهم-التكوينية-في-الجزائر.pdf
PDF
ಶ್ರೀ ಕ್ಷೇತ್ರ ಚಂಪಕಧಾಮ ಸ್ವಾಮಿ ದೇವಾಲಯSri Kshetra Champakadham Swamy Temple
PPTX
Ungu dan Kuning Modern Riset Pasar Persentasi (1).pptx
PDF
"ಶ್ರೀ ಕ್ಷೇತ್ರ ಚಂಪಕಧಾಮ ಸ್ವಾಮಿ ದೇವಾಲಯ""Sri Kshetra Champakadham Swamy Temple"
PDF
Animal Taxonomy || जंतु वर्गिकी || PDF @irfanullah_mehar
PPTX
Slide Ibadah siang 29 mei 2025 jika .pptx
PPTX
IZINKONDLO SLIDES OKWAMI NAWE grade 11.pptx
PDF
فێرکردن و فێربوونی مۆدێرن.pdf دەروازەیەک بۆ
PPTX
PETA.pptx,a,amamamamamamamamamammamamamam
PPTX
Mga Alituntunin sa Silid Aralan (Classroom Policies)
PPTX
Coklat Beige Ilustrasi 3 Dimensi Tugas Kelompok Presentasi.pptx
واقع-تكوين-المعلمين-واحتياجاتهم-التكوينية-في-الجزائر.pdf
ಶ್ರೀ ಕ್ಷೇತ್ರ ಚಂಪಕಧಾಮ ಸ್ವಾಮಿ ದೇವಾಲಯSri Kshetra Champakadham Swamy Temple
Ungu dan Kuning Modern Riset Pasar Persentasi (1).pptx
"ಶ್ರೀ ಕ್ಷೇತ್ರ ಚಂಪಕಧಾಮ ಸ್ವಾಮಿ ದೇವಾಲಯ""Sri Kshetra Champakadham Swamy Temple"
Animal Taxonomy || जंतु वर्गिकी || PDF @irfanullah_mehar
Slide Ibadah siang 29 mei 2025 jika .pptx
IZINKONDLO SLIDES OKWAMI NAWE grade 11.pptx
فێرکردن و فێربوونی مۆدێرن.pdf دەروازەیەک بۆ
PETA.pptx,a,amamamamamamamamamammamamamam
Mga Alituntunin sa Silid Aralan (Classroom Policies)
Coklat Beige Ilustrasi 3 Dimensi Tugas Kelompok Presentasi.pptx
Ad

Data structure lab 03ameer hamza