학교 수업때 한거
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
|
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
typedef int element;
typedef struct ListNode {
element data;
struct ListNode *rlink;
struct ListNode *llink;
} ListNode;
void insert_node(ListNode *before, ListNode *new_node)
{
new_node->llink = before;
new_node->rlink = before->rlink;
before->rlink->llink = new_node;
before->rlink = new_node;
}
void display_r(ListNode *head)
{
ListNode *p = head;
p = head->rlink;
while (p != head) {
printf("%d->", p->data);
p = p->rlink;
}
printf("\n");
}
void display_l(ListNode *tail)
{
ListNode *p = tail;
ListNode *q = tail;
while (p->llink != q) {
printf("%d->", p->data);
p = p->llink;
}
printf("\n");
}
void main() {
ListNode * head;
head = (ListNode*)malloc(sizeof(ListNode));
head->llink = head;
head->rlink = head;
ListNode * p1;
p1 = (ListNode*)malloc(sizeof(ListNode));
p1->data = 1;
insert_node(head, p1);
//display_r(head);
ListNode * p2;
p2 = (ListNode*)malloc(sizeof(ListNode));
p2->data = 3;
insert_node(p1, p2);
ListNode * p3;
p3 = (ListNode*)malloc(sizeof(ListNode));
p3->data = 5;
insert_node(p2, p3);
display_r(head);
display_l(p3);
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4f; text-decoration:none">Colored by Color Scripter
|
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none; color:white">cs |
'공부 > 자료구조' 카테고리의 다른 글
큐~ (0) | 2019.05.31 |
---|---|
스택 괄호검사 (0) | 2019.05.24 |
링크드 리스트 2개 오름차순으로 병합하기 (0) | 2019.05.10 |
C로 리스트 구현하기~ (0) | 2019.05.03 |