5待完善的排序

This commit is contained in:
iridiumR 2021-10-23 01:10:00 +08:00
parent 6686523ac0
commit 2e8fe9fbb8
2 changed files with 50 additions and 59 deletions

View file

@ -12,20 +12,20 @@ std::string PU[54] = {
"7A", "7B", "7C", "7D",
"8A", "8B", "8C", "8D",
"9A", "9B", "9C", "9D",
"10A", "10B", "10C", "10D",
"XA", "XB", "XC", "XD",
"JA", "JB", "JC", "JD",
"QA", "QB", "QC", "QD",
"KA", "KB", "KC", "KD",
"BlackJoker", "RadJoker"};
"BJ", "RJ"};
int main()
{
int xipai_flag = 0;
printf("生成随机扑克序列");
printf("生成随机扑克序列\n");
srand(time(NULL));
Vec v(54, 2);
v.printall();
// v.printall();
List l;
@ -34,12 +34,13 @@ int main()
for (int i = 0; i <= 53; i++)
{
l.firstInsert(v.get(i));
std::cout << PU[l[0]];
printf("\n");
std::cout << PU[l[0]] << " ";
if (i % 2 != 0)
printf("\n");
}
Begin:
printf("是否重新洗牌?(0/1)");
printf("\n是否重新洗牌?(0/1)");
scanf("%d", &xipai_flag);
if (xipai_flag == 1)
@ -53,8 +54,9 @@ Begin:
for (int i = 0; i <= 53; i++)
{
l.firstInsert(v.get(i));
std::cout << PU[l[0]];
printf("\n");
std::cout << PU[l[0]] << " ";
if (i % 2 != 0)
printf("\n");
}
xipai_flag == 0;
goto Begin;
@ -77,9 +79,9 @@ Begin:
}
}
l.clear();
// p1.sort();
// p2.sort();
// p3.sort();
p1.sort();
p2.sort();
p3.sort();
int player = 0, opt = 0;
List *pai;
select:
@ -102,30 +104,31 @@ select:
}
while (1)
{
printf("first:%d",(*pai).first()->data);
printf("1看牌2出牌3查看牌堆4结束\n");
printf("剩余%d张牌\n", pai->getSize());
printf("1看牌2出牌3查看牌堆4结束");
scanf("%d", &opt);
switch (opt)
{
case 1:
for (int i = 0; i < (*pai).getSize(); i++)
{
printf("%d\n",(*pai).get(i));
std::cout << i << ": " << PU[(*pai)[i]] << "\n";
}
break;
case 2:
printf("³öÄÄÕÅ\n");
scanf("%d", &opt);
// l.firstInsert((*pai)[opt]);
(*pai).remove(opt);
printf("first6:%d",(*pai).first()->data);
printf("剩余%d \n",pai->getSize());
printf("%d",pai->get(0));
std::cout << "打出" << PU[(*pai).remove(opt)];
printf("\n");
break;
case 3:
for (int i = 0; i <l.getSize(); i++)
for (int i = 0; i < l.getSize(); i++)
{
std::cout << l[i];
std::cout << i << ": " << PU[l[i]];
printf("\n");
}

View file

@ -32,6 +32,7 @@ Node List::predInsert(Node Old, int New)
T->succ = Old;
T->pred = Old->pred;
Old->pred = T;
T->pred->succ = T;
_size++;
return T;
}
@ -42,6 +43,7 @@ Node List::succInsert(Node Old, int New)
T->pred = Old;
T->succ = Old->succ;
Old->succ = T;
T->pred->succ = T;
_size++;
return T;
}
@ -52,6 +54,7 @@ void List::firstInsert(int New)
T->pred = header;
T->succ = header->succ;
header->succ = T;
T->succ->pred = T;
_size++;
}
void List::lastInsert(int New)
@ -61,6 +64,7 @@ void List::lastInsert(int New)
T->succ = trailer;
T->pred = trailer->pred;
trailer->pred = T;
T->pred->succ = T;
_size++;
}
Node List::predInsertN(Node Old, Node New)
@ -70,6 +74,7 @@ Node List::predInsertN(Node Old, Node New)
T->succ = Old;
T->pred = Old->pred;
Old->pred = T;
T->pred->succ = T;
_size++;
return T;
}
@ -80,6 +85,7 @@ Node List::succInsertN(Node Old, Node New)
T->pred = Old;
T->succ = Old->succ;
Old->succ = T;
T->pred->succ = T;
_size++;
return T;
}
@ -91,6 +97,7 @@ Node List::firstInsertN(Node New)
T->pred = header;
T->succ = header->succ;
header->succ = T;
T->pred->succ = T;
_size++;
return T;
}
@ -101,6 +108,7 @@ Node List::lastInsertN(Node New)
T->succ = trailer;
T->pred = trailer->pred;
trailer->pred = T;
T->pred->succ = T;
_size++;
return T;
}
@ -130,51 +138,31 @@ int List::remove(int i)
void List::removeN(Node i)
{
printf("first3:%d\n",first()->data);
printf("last%d\n",last()->data);
(i->pred)->succ = i->succ;
printf("first3.5:%d\n",first()->data);
printf("last%d\n",last()->data);
(i->succ)->pred = i->pred;
printf("first4:%d\n",first()->data);
printf("last%d\n",last()->data);
delete i;
printf("first5:%d\n",first()->data);
_size--;
}
void List::sort()
{
// int sorted_size=0;
// int unsorted_size=_size-1;
// for(int i=0;i<unsorted_size;i++)
// {
// Node maxN;
// int max=0;
int sorted = 0;
Node p;
for (int i = 0; i <= _size - 1 - sorted; i++)
for (int j = i; j <= _size - 1 - sorted; j++)
{
int max = 0;
Node maxN;
// Node T=find(0);
// printf("OK\n");
// maxN->data=T->data;
// T->data=max;
p = find(j);
if (max < p->data)
{
max = p->data;
maxN = p;
}
// sorted_size++;
// unsorted_size--;
// }
// Node maxN;
// Node p=trailer->pred;
// int max;
// for(int r=0;r<_size;r++)
// {
// for(int j=0;j<=r;j++)
// {
// printf("j%d\n",j);
// Node T =find(j);
// if(max>T->data)
// {
// max=T->data;
// maxN=T;
// }
// }
// predInsert(find(),)
// }
maxN->data = p->data;
p->data = max;
sorted++;
}
}