-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLinkedList.h
92 lines (75 loc) · 1.5 KB
/
LinkedList.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
#ifndef LINKEDLIST_H
#define LINKEDLIST_H
#include <stdio.h>
#include <stdlib.h>
#include "draw.h"
int Deck_sequence[5];
typedef struct ListNode {
int data;
struct ListNode* link;
}ListNode;
typedef struct CountList {
ListNode* first;
int count;
}clist;
ListNode* insert_first(ListNode *head, int value) {
ListNode* p = (ListNode*)malloc(sizeof(ListNode));
p->data = value;
p->link = head;
head = p;
return head;
}
void change_data(clist* list, int a, int b) {
int temp;
if (a > b) {
a = a ^ b; //xor연산자
b = a ^ b;
a = a ^ b;
}
ListNode* k = list->first;
for (int i = 0; i < a; i++) {
k = k->link;
}
ListNode* ret = k;
for (int i = a; i < b; i++) {
k = k->link;
}
temp = k->data;
k->data = ret->data;
ret->data = temp;
}
ListNode* insert(ListNode* head, ListNode* pre, int value) {
ListNode* p = (ListNode*)malloc(sizeof(ListNode));
p->data = value;
p->link = pre->link;
pre->link = p;
return head;
}
ListNode* delete_first(ListNode* head) {
ListNode* removed;
if (head == NULL)
return NULL;
removed = head;
head = removed->link;
free(removed);
return head;
}
ListNode* delete(ListNode* head, ListNode* pre) {
ListNode *removed;
removed = pre->link;
pre->link = removed->link;
free(removed);
return head;
}
void Deck_print(ListNode* head) {
int count = 0;
for (ListNode* p = head; p != NULL; p = p->link) {
DrawCard(p->data, count);
Deck_sequence[count] = p->data; //뽑은 패의 순서를 Deck_sequence에 담는다.
count++;
if (count == 5) {
break;
}
}
}
#endif