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

View file

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