Á¤¼ºÈÆ
    ½Ç½À ÇÁ·Î±×·¥ ¿¹)
find_node.txt [3 KB]   delete.txt [3 KB]  



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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
typedef struct student_info {
    char name[10];
    int height;
    float weight;
} element;
 
typedef struct ListNode {     // ³ëµå Å¸ÀÔÀ» ±¸Á¶Ã¼·Î Á¤ÀÇÇÑ´Ù.
    element data;
    struct ListNode *link;
} ListNode;
 
 
ListNode* insert_first(ListNode *head, element value)
{
    ListNode *= (ListNode *)malloc(sizeof(ListNode));//(1)
    p->data = value;    // (2)
    p->link = head; //(3)
    head = p; //(4)
 
    return head;
}
 
// ³ëµå pre µÚ¿¡ »õ·Î¿î ³ëµå »ðÀÔ
ListNode*  insert(ListNode *head, ListNode *pre, element value)
{
    ListNode *= (ListNode *)malloc(sizeof(ListNode));    //(1)
    p->data = value;        //(2)
    p->link = pre->link;    //(3)    
    pre->link = p;        //(4)    
    return head;        //(5)    
}
 
ListNode* delete_first(ListNode *head)
{
    ListNode *removed;
    if (head == NULLreturn NULL;
    removed = head;    // (1)
    head = removed->link;    // (2)
    free(removed);        // (3)
    return head;        // (4)
}
 
// pre°¡ °¡¸®Å°´Â ³ëµåÀÇ ´ÙÀ½ ³ëµå¸¦ »èÁ¦ÇÑ´Ù. 
ListNode* delete(ListNode *head, ListNode *pre)
{
    ListNode *removed;
    removed = pre->link;
    pre->link = removed->link;        // (2)
    free(removed);            // (3)
    return head;            // (4)
}
 
void print_list(ListNode *head)
{
    for (ListNode *= head; p != NULL; p = p->link)
        printf("(%s %3d %4.1f)->", p->data.name, p->data.height, p->data.weight);
    printf("\n");
}
 
element* new_element(char *name, int height, float weight)
{
    element *= (element *)malloc(sizeof(element));    //(1)
    strcpy(p->name, name);
    p->height = height;
    p->weight = weight;
    
    return p;
}
 
ListNode* find_node(ListNode *head,char *name)
{
    for (ListNode *= head; p != NULL; p = p->link)
        if (!strcmp(p->data.name, name)) 
            return p;
    return NULL;
}
// Å×½ºÆ® ÇÁ·Î±×·¥
int main(void)
{
    ListNode *head = NULL*pre;
    element* new;
 
    new = new_element("È«±æµ¿"16772.5);
    head = insert_first(head, *new);
    new = new_element("À¯°ü¼ø"16358.4);
    head = insert_first(head, *new);
    new = new_element("±èÀ¯½Å"15970.8);
    head = insert_first(head, *new);
    print_list(head);
 
    head = delete_first(head);
    print_list(head);
 
    pre = find_node(head, "À¯°ü¼ø");
    if (pre != NULL) {
        new = new_element("À̼ø½Å"17283.4);
        head = insert(head, pre, *new);
    }
    print_list(head);
 
    return 0;
}
cs

 

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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
typedef struct student_info {
    char name[10];
    int height;
    float weight;
} element;
 
typedef struct ListNode {     // ³ëµå Å¸ÀÔÀ» ±¸Á¶Ã¼·Î Á¤ÀÇÇÑ´Ù.
    element data;
    struct ListNode *link;
} ListNode;
 
 
ListNode* insert_first(ListNode *head, element value)
{
    ListNode *= (ListNode *)malloc(sizeof(ListNode));//(1)
    p->data = value;    // (2)
    p->link = head; //(3)
    head = p; //(4)
 
    return head;
}
 
// ³ëµå pre µÚ¿¡ »õ·Î¿î ³ëµå »ðÀÔ
ListNode*  insert(ListNode *head, ListNode *pre, element value)
{
    ListNode *= (ListNode *)malloc(sizeof(ListNode));    //(1)
    p->data = value;        //(2)
    p->link = pre->link;    //(3)    
    pre->link = p;        //(4)    
    return head;        //(5)    
}
 
ListNode* delete_first(ListNode *head)
{
    ListNode *removed;
    if (head == NULLreturn NULL;
    removed = head;    // (1)
    head = removed->link;    // (2)
    free(removed);        // (3)
    return head;        // (4)
}
 
// pre°¡ °¡¸®Å°´Â ³ëµåÀÇ ´ÙÀ½ ³ëµå¸¦ »èÁ¦ÇÑ´Ù. 
ListNode* delete(ListNode *head, ListNode *pre)
{
    ListNode *removed;
    removed = pre->link;
    pre->link = removed->link;        // (2)
    free(removed);            // (3)
    return head;            // (4)
}
 
void print_list(ListNode *head)
{
    for (ListNode *= head; p != NULL; p = p->link)
        printf("(%s %3d %4.1f)->", p->data.name, p->data.height, p->data.weight);
    printf("\n");
}
 
element* new_element(char *name, int height, float weight)
{
    element *= (element *)malloc(sizeof(element));    //(1)
    strcpy(p->name, name);
    p->height = height;
    p->weight = weight;
    
    return p;
}
 
ListNode* find_node(ListNode *head,char *name)
{
    for (ListNode *= head; p != NULL; p = p->link)
        if (!strcmp(p->data.name, name)) 
            return p;
    return NULL;
}
// Å×½ºÆ® ÇÁ·Î±×·¥
int main(void)
{
    ListNode *head = NULL*pre;
    element* new;
 
    new = new_element("È«±æµ¿"16772.5);
    head = insert_first(head, *new);
    new = new_element("À¯°ü¼ø"16358.4);
    head = insert_first(head, *new);
    new = new_element("±èÀ¯½Å"15970.8);
    head = insert_first(head, *new);
    print_list(head);
 
    head = delete_first(head);
    print_list(head);
 
    pre = find_node(head, "À¯°ü¼ø");
    if (pre != NULL) {
        new = new_element("À̼ø½Å"17283.4);
        head = insert(head, pre, *new);
    }
    print_list(head);
 
    pre = find_node(head, "À̼ø½Å");
    if (pre != NULL) {
        head = delete(head, pre);
        print_list(head);
    }
 
    return 0;
}
cs

  µî·ÏÀÏ : 2020-11-03 [20:05] Á¶È¸ : 539 ´Ù¿î : 372   
 
¡â ÀÌÀü±Û½Ç½À ÇÁ·Î±×·¥ ¿¹)
¡ä ´ÙÀ½±Û½Ç½À ÇÁ·Î±×·¥ ¿¹)
ÀڷᱸÁ¶ ½Ç½À°Ô½ÃÆÇ
¹øÈ£ ¨Ï Á¦ ¸ñ
[Âü°í] ±³Àç¿¡ ÀÖ´Â ¼Ò½ºÄÚµå
57    ¦¦❷ ½Ç½À ÇÁ·Î±×·¥ ¿¹)
56       ¦¦❸ ½Ç½À ÇÁ·Î±×·¥ ¿¹)
55          ¦¦❹ ¿øÇü ¿¬°á ¸®½ºÆ®¿¡¼­ print_list() ÇÔ¼ö ¹ö±× ¹®Á¦
54             ¦¦❺ ¹ö±× ÀÖ´Â ±³Àç ÇÁ·Î±×·¥°ú ¹ö±×¸¦ ¼öÁ¤ÇÑ ¿Ã¹Ù¸¥ ÇÁ·Î±×·¥
53                ¦¦❻ ƯÁ¤ À̸§ÀÇ ³ëµå¸¦ ã¾Æ¼­ ÇØ´ç ³ëµå µÚ¿¡ ÇØ´ç ³ëµå Á¤º¸¸¦ k¹ø Ãß°¡ÇÏ´Â ÇÁ·Î±×·¥ (Ãß°¡)
52                   ¦¦❼ (Ãß°¡) ½Ç½À ÇÁ·Î±×·¥ ¿¹)
51 ¨Õ(½Ç½À 8) ½Ã¹Ä·¹À̼Ç
50 ¦¦❶ ½Ç½À ÇÁ·Î±×·¥ ¿¹)
49    ¦¦❷ ½Ç½À ÇÁ·Î±×·¥ ¿¹)
48       ¦¦❸ ½Ç½À ÇÁ·Î±×·¥ ¿¹)
47          ¦¦❹ ¨ÕÇ׸ñ º° ¿ì¼±¼øÀ§¸¦ µÎ¾î¼­ ¿ì¼±¼øÀ§¿¡ µû¶ó¼­ ó¸®Çϵµ·Ï º¯°æ (Ãß°¡)
46             ¦¦❺ ¨Õ(Ãß°¡) ½Ç½À ÇÁ·Î±×·¥ ¿¹)
45 ¨Õ(½Ç½À 7) ¹Ì·Îã±â
44 ¦¦❶ ½Ç½À ÇÁ·Î±×·¥ ¿¹)
43    ¦¦❷ ½Ç½À ÇÁ·Î±×·¥ ¿¹)
42       ¦¦❸ ½Ç½À ÇÁ·Î±×·¥ ¿¹)
41          ¦¦❹ ¨ÕÅ¥¸¦ ÀÌ¿ëÇÑ ³Êºñ ¿ì¼± Ž»ö BFS(Breadth First Search) ±¸Çö (Ãß°¡)
40             ¦¦❺ ¨Õ(Ãß°¡) ½Ç½À ÇÁ·Î±×·¥ ¿¹)
39                ¦¦❻ (Ãß°¡) ½Ç½À ÇÁ·Î±×·¥ ¿¹) // °æ·Î ÇÁ¸°Æ® ¹öÀü
38 ¨Õ(½Ç½À 6) ½ºÅÃ

[1][2][3][4]