-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dobuly_Link List.cpp
102 lines (78 loc) · 1.77 KB
/
Dobuly_Link List.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include"iostream"
using namespace std;
struct Node{
int data;
Node* next;
Node* previous;
};
class Dobuly_Link_List{
Node* head;
// Node* previous;
public:
// Create Constructor of Class
Dobuly_Link_List(){
head=NULL;
}
// Function to Insert the value in List
void Insert(int val){
Node* n=new Node();
n->data=val;
n->next=NULL;
if(head==NULL){
head=n;
n->previous=NULL;
}
else{
Node* temp=head;
while(temp->next!=NULL){
temp=temp->next;
}
temp->next=n;
n->previous=temp;
}
}
// Function to Delete the last Node
void delete_Last(){
Node* ptr=head;
while(ptr->next->next!=NULL){
ptr=ptr->next;
}
Node* temp=ptr->next;
ptr->next=NULL;
delete(temp);
}
// Function to Print the List
void print(){
Node* ptr=head;
while(ptr!=NULL){
cout<<ptr->data<<endl;
ptr=ptr->next;
}
}
// Function to check weather the List is empty
bool empty(){
if(head==NULL){
return true;
}
else{
return false;
}
}
};
int main()
{
Dobuly_Link_List a;
a.Insert(10);
a.Insert(20);
a.Insert(30);
a.Insert(40);
a.delete_Last();
a.print();
cout<<endl;
}
/*
Arbab Hassan
Department of Information Technology
University of Gujrat
*/