-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist.h
120 lines (117 loc) · 2.36 KB
/
list.h
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
/**************************************
-----------------list.h---------------------
product name:list
module name:list
date:2022.03.06
auther:none
file describe: none
***************************************/
#ifndef _LIST_H_
#define _LIST_H_
#ifdef __cplusplus // c++ include
extern "C"
#endif // include c++ file
#include <stdio.h>
#include <stdlib.h>
#include "card.h"
// macro define
//这个卡牌内容的链表具有一个
//**空的头指针*
//双向链表
struct List
{
Card val;
//后继
struct List *next;
//前躯
struct List *prior;
void Insert(Card);
void InsertBetween(Card);
int length();
void print();
int isIncludeTaunt();
};
//卡牌的长度
//初始的长度为0
int List::length()
{
List *p = this->next;
int a = 0;
while (p)
{
p = p->next;
++a;
}
return a;
}
//在链表的*末尾*插入一个卡牌的类型
void List::Insert(Card a)
{
List *p;
p = (List *)malloc(sizeof(List));
p->next = NULL;
p->prior = NULL;
p->val = a;
List *th;
th = this;
while (th->next)
{
th = th->next;
}
th->next = p;
p->prior = th;
}
//只能用在战斗卡牌(CardinFight)中!!!!
//根据卡牌的位置在卡牌的中间插入一个卡牌
//只能用在战斗卡牌(CardinFight)中!!!!
void List::InsertBetween(Card a)
{
List *p;
p = (List *)malloc(sizeof(List));
p->next = p->prior = NULL;
p->val = a;
List *th = this;
while (th->next)
{
if (th->next->val.Sprite.getPosition().x > a.Sprite.getPosition().x)
{
p->next = th->next;
th->next->prior = p;
th->next = p;
p->prior = th;
th = p;
return;
}
th = th->next;
}
this->Insert(a);
}
//输出这个链表的内容用名字
void List::print()
{
List *p = this->next;
printf("[");
while (p)
{
printf("\"%s\"", p->val.name);
if (p->next)
printf(",");
p = p->next;
}
printf("]\n");
}
//该链表的卡牌下包含嘲讽么?
//如果包含,则返回1,否则返回0
int List::isIncludeTaunt(){
List *p=this;
while(p){
if(p->val.Taunt){
return 1;
}
p=p->next;
}
return 0;
}
#ifdef __cpluscplus
#endif
#endif // end _LIST_H