Skip to content

Commit 2a663fe

Browse files
author
jinfeng95
committed
add my Reverse
1 parent ebc8baf commit 2a663fe

File tree

1 file changed

+42
-11
lines changed

1 file changed

+42
-11
lines changed

src/a_datastruct_linerlist.cpp

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ bool CreateList(SqList &L, int n)
5252
}
5353
return true;
5454
}
55+
//输出功能函数 按位置从小到大输出顺序表所有元素
56+
void PrintList(SqList L)
57+
{
58+
printf("当前顺序表所有元素:");
59+
for (int i = 0; i<L.length; i++)
60+
{
61+
printf("%d ", L.data[i]);
62+
}
63+
printf("\n");
64+
}
5565
//插入函数 位置i插入数据 i及之后元素后移 1=<i<=length+1
5666
bool InsertList(SqList &L, int i, ElemType e)
5767
{
@@ -110,7 +120,30 @@ void Reverse(SqList &L)
110120
}
111121
}
112122
//奇偶分开并排序
113-
void SplitSort(SqList &L)
123+
void SplitSort(SqList &l){
124+
125+
int oddIndex = 0;
126+
int evenIndex = l.length-1;
127+
while (oddIndex<evenIndex){
128+
while (l.data[oddIndex]%2==1)oddIndex++;
129+
while (l.data[evenIndex]%2==0)evenIndex--;
130+
if(l.data[oddIndex]%2==0&&l.data[evenIndex]%2==1&&oddIndex<evenIndex){
131+
int temp = l.data[oddIndex];
132+
l.data[oddIndex] = l.data[evenIndex];
133+
l.data[evenIndex] = temp;
134+
oddIndex++;
135+
evenIndex--;
136+
}
137+
}
138+
oddIndex--;
139+
evenIndex++;
140+
PrintList(l);
141+
sort(l.data,l.data+oddIndex+1);
142+
PrintList(l);
143+
sort(l.data+evenIndex,l.data+l.length);
144+
PrintList(l);
145+
}
146+
void SplitSort3(SqList &L)
114147
{
115148
int Even = 0;
116149
int Odd = L.length - 1;
@@ -196,16 +229,7 @@ void ClearList(SqList &L) {
196229
L.length = 0;
197230
}
198231
//********************************功能函数*****************************************//
199-
//输出功能函数 按位置从小到大输出顺序表所有元素
200-
void PrintList(SqList L)
201-
{
202-
printf("当前顺序表所有元素:");
203-
for (int i = 0; i<L.length; i++)
204-
{
205-
printf("%d ", L.data[i]);
206-
}
207-
printf("\n");
208-
}
232+
209233
//创建顺序表函数
210234
void Create(SqList &L)
211235
{
@@ -321,6 +345,13 @@ int main()
321345
default:printf("输入错误!!!\n");
322346
}
323347
}
348+
// int t [6]={1,6,3,4,5,2};
349+
// int t[6] ={11,3,13,7,9,1};
350+
// int t = {2,4,6,8,10,12};
351+
// for (int i = 0; i < 6; ++i) {
352+
// L.data[i] =t[i];
353+
// }
354+
// L.length=6;
324355
return 0;
325356
}
326357

0 commit comments

Comments
 (0)