-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy path2-3-4.cpp
70 lines (65 loc) · 1.06 KB
/
2-3-4.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
#include<iostream>
using namespace std;
typedef struct LNode{
int data;
struct LNode* next;
}LNode, *LinkList;
void fun(LinkList &L,int x){
LinkList p=L->next,pre=L,q;
while(p){
if(p->data==x){
q=p;
p=p->next;
pre->next=p;
free(q);
}else{
pre=p;
p=p->next;
}
}
}
int main(){
////////////////////////////////////////////////////////////
////////////////////建立链表////////////////////////////////
LinkList L,s;
int x=0;
L=(LinkList)malloc(sizeof(LNode));
L->next=NULL;
cin>>x;
while(x!=9999){
s=(LinkList)malloc(sizeof(LNode));
s->data=x;
s->next=L->next;
L->next=s;
cin>>x;
}
//带头结点:
s=L->next;
//不带头结点:
//L=L->next;
//s=L;
////////////////////////////////////////////////////////////
//函数调用:返回链表
//cin>>x;
if(s)x=s->data;else return 1;
while(s){
if(x>s->data)x=s->data;
s=s->next;
}
fun(L,x);
s=L->next;
//打印链表:
while(s){
cout<<s->data<<" ";
s=s->next;
}
cout<<endl;
free(s);
LinkList p=L;
while(L){
p=L;
L=L->next;
free(p);
}
return 0;
}