一堆修不好的bug

This commit is contained in:
iridiumR 2021-10-22 19:25:46 +08:00
parent c00d21929f
commit fa8cb8a459
5 changed files with 224 additions and 38 deletions

View file

@ -2,23 +2,139 @@
#include "list.cpp"
#include <time.h>
#include <stdio.h>
std::string PU[54] = {
"1A", "1B", "1C", "1D",
"2A", "2B", "2C", "2D",
"3A", "3B", "3C", "3D",
"4A", "4B", "4C", "4D",
"5A", "5B", "5C", "5D",
"6A", "6B", "6C", "6D",
"7A", "7B", "7C", "7D",
"8A", "8B", "8C", "8D",
"9A", "9B", "9C", "9D",
"10A", "10B", "10C", "10D",
"JA", "JB", "JC", "JD",
"QA", "QB", "QC", "QD",
"KA", "KB", "KC", "KD",
"BlackJoker", "RadJoker"};
int main()
{
int xipai_flag = 0;
printf("生成随机扑克序列");
srand(time(NULL));
Vec v(54,2);
Vec v(54, 2);
v.printall();
List l;
printf("¿ªÊ¼½¨Á¢Á´±í\n");
for(int i=0;i<=53;i++)
for (int i = 0; i <= 53; i++)
{
l.firstInsert(v.get(i));
printf("%d\n",l[0]);
std::cout << PU[l[0]];
printf("\n");
}
Begin:
printf("是否重新洗牌?(0/1)");
scanf("%d", &xipai_flag);
if (xipai_flag == 1)
{
v.reorder();
l.clear();
printf("开始建立链表\n");
for (int i = 0; i <= 53; i++)
{
l.firstInsert(v.get(i));
std::cout << PU[l[0]];
printf("\n");
}
xipai_flag == 0;
goto Begin;
}
printf("开始发牌\n");
List p1, p2, p3;
for (int i = 0; i <= 53; i++)
{
switch (i % 3)
{
case 0:
p1.firstInsert(l[i]);
break;
case 1:
p2.firstInsert(l[i]);
break;
case 2:
p3.firstInsert(l[i]);
break;
}
}
l.clear();
// p1.sort();
// p2.sort();
// p3.sort();
int player = 0, opt = 0;
List *pai;
select:
printf("选择玩家(1/2/3)");
scanf("%d", &player);
switch (player)
{
case 1:
pai = &p1;
break;
case 2:
pai = &p2;
break;
case 3:
pai = &p3;
break;
default:
printf("失败\n");
goto select;
}
while (1)
{
printf("first:%d",(*pai).first()->data);
printf("1看牌2出牌3查看牌堆4结束\n");
scanf("%d", &opt);
switch (opt)
{
case 1:
for (int i = 0; i < (*pai).getSize(); i++)
{
printf("%d\n",(*pai).get(i));
}
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));
break;
case 3:
for (int i = 0; i <l.getSize(); i++)
{
std::cout << l[i];
printf("\n");
}
case 4:
goto select;
default:
printf("失败\n");
}
}
return 0;
}

View file

@ -12,6 +12,19 @@ List::List()
trailer->pred = header;
}
List::~List()
{
clear();
delete trailer;
delete header;
}
void List::clear()
{
while (0 < _size)
remove(0);
}
Node List::predInsert(Node Old, int New)
{
Node T = new node;
@ -93,14 +106,75 @@ Node List::lastInsertN(Node New)
}
Node List::find(int i)
{
Node ans = first();
for (int i = 0; i < _size; i++)
Node p = first();
while (0 < i--)
{
ans = ans->succ;
p = p->succ;
}
return ans;
return p;
}
int List::get(int i)
{
return find(i)->data;
}
int List::remove(int i)
{
Node T = find(i);
int ans = T->data;
removeN(T);
return ans;
}
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;
// Node T=find(0);
// printf("OK\n");
// maxN->data=T->data;
// T->data=max;
// 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(),)
// }
}

View file

@ -17,10 +17,15 @@ private:
int _size;
protected:
int clear();
public:
int getSize()
{
return _size;
}
List();
~List();
void clear();
Node first() { return header->succ; }
Node last() { return trailer->pred; }
void firstInsert(int New);
@ -33,6 +38,10 @@ public:
Node predInsertN(Node old, Node ne);
int get(int i);
Node find(int i);
int remove(int i);
void removeN(Node i);
void sort();
int operator[](int i)
{
@ -42,31 +51,3 @@ public:
return p->data;
}
};
class PUKE
{
private:
std::string PU[54] = {
"1A", "1B", "1C", "1D",
"2A", "2B", "2C", "2D",
"3A", "3B", "3C", "3D",
"4A", "4B", "4C", "4D",
"5A", "5B", "5C", "5D",
"6A", "6B", "6C", "6D",
"7A", "7B", "7C", "7D",
"8A", "8B", "8C", "8D",
"9A", "9B", "9C", "9D",
"10A", "10B", "10C", "10D",
"JA", "JB", "JC", "JD",
"QA", "QB", "QC", "QD",
"KA", "KB"
"KC",
"KD",
"BlackJoker", "RadJoker"};
public:
std::string p(int a)
{
return PU[a];
}
};

View file

@ -238,3 +238,9 @@ void Vec::merge(int lo, int mi, int hi)
_v[i] = temp[k];
delete[] temp;
}
void Vec::reorder()
{
for (int i = 0; i <= _used; i++)
swap(i, rand() % ((_used + 1)));
}

View file

@ -21,7 +21,14 @@ private:
void shrink();
public:
Vec(int _len,int mode);
~Vec()
{
delete[] _v;
delete &_len;
delete &_used;
delete &_sorted;
}
Vec(int _len, int mode);
int get(int a);
@ -51,6 +58,8 @@ public:
void mergeSort(int lo, int hi);
void reorder();
private:
void merge(int lo, int mi, int hi);
};