-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinkedListUsingCsEcond.cpp
More file actions
84 lines (81 loc) · 1.68 KB
/
linkedListUsingCsEcond.cpp
File metadata and controls
84 lines (81 loc) · 1.68 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
#include<iostream>
using namespace std;
struct LinkedList{
int data;
LinkedList *node;
};
LinkedList *start = NULL;
LinkedList * CreateNode(){
LinkedList *temp;
temp = (LinkedList *)(malloc(sizeof(LinkedList)));
return temp;
}
void InsertNode(int data){
LinkedList *temp,*tempStart;
temp=CreateNode();
temp->data=data;
temp->node=NULL;
if(start==NULL){
start=temp;
}
else{
tempStart = start;
while(tempStart->node!=NULL){
tempStart=tempStart->node;
}
tempStart->node = temp;
}
}
void PrintListData(){
LinkedList *tempPrinter;
tempPrinter = start;
while(tempPrinter!=NULL){
cout<<tempPrinter->data<<endl;
tempPrinter= tempPrinter->node;
}
}
void DeleteFirstNode(){
LinkedList *tempStart;
tempStart=start;
if(start!=NULL){
start=start->node;
free(tempStart);
}
else{
cout<<"The list is empty"<<endl;
}
}
void DeleteSpecificNode(int data){
LinkedList *tempStart,*tempTempStart;
int count = 0;
tempStart = start;
if(start->data==data){
start=start->node;
free(tempStart);
return;
}
tempTempStart= start;
while(tempStart->data!=data){
tempStart = tempStart->node;
if(count!=0){
tempTempStart=tempTempStart->node;
}
count++;
}
tempStart=tempStart->node;
tempTempStart->node=tempStart;
// free(tempTempStart);
}
int main(){
InsertNode(11);
InsertNode(22);
InsertNode(33);
InsertNode(44);
InsertNode(55);
DeleteSpecificNode(44);
PrintListData();
system("pause");
DeleteSpecificNode(11);
system("cls");
PrintListData();
}