8000 Update Linked List.cpp · SelfCodeLearning/C-Plus-Plus@7be0b8d · GitHub
[go: up one dir, main page]

Skip to content

Commit 7be0b8d

Browse files
authored
Update Linked List.cpp
fix: reverse check for empty list + cpplint coding style
1 parent 248c335 commit 7be0b8d

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

data_structure/Linked List.cpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ void insert(int x) {
2727

2828
void remove(int x) {
2929
if (start == NULL) {
30-
cout << "\nLinked List is empty\n";
30+
std::cout << "\nLinked List is empty\n";
3131
return;
3232
} else if (start->val == x) {
3333
node *temp = start;
@@ -44,7 +44,7 @@ void remove(int x) {
4444
}
4545

4646
if (temp == NULL) {
47-
cout << endl << x << " not found in list\n";
47+
std::cout << endl << x << " not found in list\n";
4848
return;
4949
}
5050

@@ -57,21 +57,21 @@ void search(int x) {
5757
int found = 0;
5858
while (t != NULL) {
5959
if (t->val == x) {
60-
cout << "\nFound";
60+
std::cout << "\nFound";
6161
found = 1;
6262
break;
6363
}
6464
t = t->next;
6565
}
6666
if (found == 0) {
67-
cout << "\nNot Found";
67+
std::cout << "\nNot Found";
6868
}
6969
}
7070

7171
void show() {
7272
node *t = start;
7373
while (t != NULL) {
74-
cout << t->val << "\t";
74+
std::cout << t->val << "\t";
7575
t = t->next;
7676
}
7777
}
@@ -89,46 +89,46 @@ void reverse() {
8989
start->next = NULL;
9090
start = first;
9191
} else {
92-
cout << "\nEmpty list";
92+
std::cout << "\nEmpty list";
9393
}
9494
}
9595

9696
int main() {
9797
int choice, x;
9898
do {
99-
cout << "\n1. Insert";
100-
cout << "\n2. Delete";
101-
cout << "\n3. Search";
102-
cout << "\n4. Print";
103-
cout << "\n5. Reverse";
104-
cout << "\n0. Exit";
105-
cout << "\n\nEnter you choice : ";
106-
cin >> choice;
99+
std::cout << "\n1. Insert";
100+
std::cout << "\n2. Delete";
101+
std::cout << "\n3. Search";
102+
std::cout << "\n4. Print";
103+
std::cout << "\n5. Reverse";
104+
std::cout << "\n0. Exit";
105+
std::cout << "\n\nEnter you choice : ";
106+
std::cin >> choice;
107107
switch (choice) {
108108
case 1:
109-
cout << "\nEnter the element to be inserted : ";
110-
cin >> x;
109+
std::cout << "\nEnter the element to be inserted : ";
110+
std::cin >> x;
111111
insert(x);
112112
break;
113113
case 2:
114-
cout << "\nEnter the element to be removed : ";
115-
cin >> x;
114+
std::cout << "\nEnter the element to be removed : ";
115+
std::cin >> x;
116116
remove(x);
117117
break;
118118
case 3:
119-
cout << "\nEnter the element to be searched : ";
120-
cin >> x;
119+
std::cout << "\nEnter the element to be searched : ";
120+
std::cin >> x;
121121
search(x);
122122
break;
123123
case 4:
124124
show();
125-
cout << "\n";
125+
std::cout << "\n";
126126
break;
127127
case 5:
128-
cout << "The reversed list: \n";
128+
std::cout << "The reversed list: \n";
129129
reverse();
130130
show();
131-
cout << "\n";
131+
std::cout << "\n";
132132
break;
133133
}
134134
} while (choice != 0);

0 commit comments

Comments
 (0)
0