-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjay7.cpp
More file actions
88 lines (84 loc) · 1.54 KB
/
jay7.cpp
File metadata and controls
88 lines (84 loc) · 1.54 KB
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
#include<iostream>
using namespace std;
class node{
public:
float data;
node* next;
node(float val){
data=val;
}
};
class list{
node* head;
node* tail;
public:
list(){
head=tail=NULL;
}
void push_front(int x){
node* n=new node(x);
if(head==NULL){
head=tail=n;
return;
}
else{
n->next=head;
head=n;
}
}
void push_back(int x){
node* n=new node(x);
if(head==NULL){
head=tail=n;
return;
}
tail->next=n;
tail=n;
}
void pop_front(){
if(head==NULL){
return;
}
node* temp=head;
head=head->next;
if(temp==tail){
tail=NULL;
}
delete temp;
}
void pop_back(){
if(head==NULL){
return;
}
node* temp=head;
while(temp->next!=tail){
temp=temp->next;
}
temp->next=NULL;
delete tail;
tail=temp;
if(tail==NULL){
head=NULL;
}
}
int search(int val){
node* temp=head;
int i=0;
while(temp!=NULL){
if(temp->data==val){
return i;
}
i++;
temp=temp->next;
}
return -1;
}
void printList(){
node* temp=head;
while(temp){
cout<<temp->data<<" ";
temp=temp->next;
}
cout<<endl;
}
}