-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsqlList.cpp
178 lines (157 loc) · 2.55 KB
/
sqlList.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#include"iostream.h"
#include"stdlib.h"
#define MaxSize 100
typedef struct
{
int *elem;
int n;
int listsize;
}Sqlist;
void Creat(Sqlist &L)
{
int i=0;
L.elem=(int *)malloc(MaxSize*sizeof(Sqlist));
L.n=0;
L.listsize=MaxSize;
while(1)
{
int c = 1;
// cout<<"请输入内容";
// cin>>c;
if(c==0)
break;
L.elem[i++] = c;
}
L.n=i;
}
void Show(Sqlist L)
{
for(int i=0;i<L.n;i++)
cout<<L.elem[i]<<" ";
cout<<endl<<"The length of the seqlist is:"<<L.n<<endl;
}
bool DeletMin(Sqlist &L,int &min)//P12 1题(1)
{
int i=0,p;
if(L.n==0) return false;
min=L.elem[0];
for(i=1;i<L.n;i++)
if(L.elem[i]<min)
min=L.elem[i];
for(i=0;i<L.n;i++)
{
if(L.elem[i]==min)
L.elem[i]=L.elem[L.n-1];
}
}
bool DeletI(Sqlist &L,int i,int &value)//P12 1题(2)
{
if(L.n==0||i<0||i>=L.n) return false;
value=L.elem[i-1];
for(int j=i;j<L.n;j++)
L.elem[j-1]=L.elem[j];
L.n--;
}
bool Insert(Sqlist &L,int i,int x)//(3)
{
int j;
if(L.n==0 || i<0 || i>L.n)
{
return false;
}
for(j = L.n; j >= i; j--)
{
L.elem[j] = L.elem[j-1];
}
L.elem[j]=x;
L.n++;
}
bool DeleteX(Sqlist &L,int x)//(4)
{
if(L.n==0)return false;
for(int i=0;i<L.n;i++)
{
if(L.elem[i]==x)
{
for(int j=i;j<L.n-1;j++)
L.elem[j]=L.elem[j+1];
L.n--;
i--;
}
}
}
bool DeleteST(Sqlist &L,int s,int t)//(5)
{
if(L.n==0||s>t)return false;
for(int i=L.n-1;i>=0;i--)
if(L.elem[i]<t&&L.elem[i]>s)
{
for(int j=i;j<L.n;j++)
L.elem[j]=L.elem[j+1];
L.n--;
}
return true;
}
bool DeleteSTq(Sqlist &L,int s,int t)//(6)
{
int i,j,k,u;
if(L.n==0||s>t)return false;
for(i=0;i<L.n&&L.elem[i]<=s;i++);
if(i>=L.n)return false;
cout<<i<<endl;
for(j=L.n-1;j>0&&L.elem[j]>=t;j--);
if(j<=0)return false;
cout<<j<<endl;
for(k=i,u=j;u<L.n;k++,u++)
L.elem[k]=L.elem[u+1];
L.n-=(j-i+1);
return true;
}
bool Merge(Sqlist A,Sqlist B,Sqlist &C)
{
int i=0,j=0,k=0;
if((A.n+B.n)>C.listsize)return false;
while(i<A.n&&j<B.n)
{
if(A.elem[i]<=B.elem[j])
C.elem[k++]=A.elem[i++];
else
C.elem[k++]=B.elem[j++];
}
while(i<A.n)C.elem[k++]=A.elem[i++];
while(j<B.n)C.elem[k++]=B.elem[j++];
C.n=k;
}
bool DeleteSame(Sqlist &L)//(8)
{
if(L.n==0)return false;
int i=0,j;
while(i<L.n)
{
j=i+1;
if(L.elem[i]!=L.elem[j])
{
i++;
j++;
}
else
{
while(L.elem[j]==L.elem[i]&&j<L.n-1)j++;
int k=i;
while(j<L.n) L.elem[k++]=L.elem[j++];
L.n=k;
i++;
}
}
}
int main()
{
int min = 0;
Sqlist L;
Creat(L);
cout<<"顺序表的长度";
Show(L);
// DeletMin(L,min);
//Show(L);
cout<<endl<<min<<endl;
}