Á¤¼ºÈÆ
    ½Ç½À ÇÁ·Î±×·¥ ¿¹)
insert_first.txt [2 KB]   delete_first.txt [2 KB]  



½Ç½À ÇÁ·Î±×·¥ ¿À·ù ¼öÁ¤
¼öÁ¤ Àü (¿À·ù ÀÖÀ½) ¼öÁ¤ ÈÄ
element* new_element(char *name, int height, float weight)
{
    element *p = (element *)malloc(sizeof(element));    //(1)
    strcpy(p->data.name, name);
    p->data.height = height;
    p->data.weight = weight;
    
    return p;
}
element* new_element(char *name, int height, float weight)
{
    element *p = (element *)malloc(sizeof(element));    //(1)
    strcpy(p->name, name);
    p->height = height;
    p->weight = weight;
    
    return p;
}

typedef struct student_info {
    char name[10];
    int height;
    float weight;
} element;

typedef struct ListNode {     // ³ëµå ŸÀÔÀ» ±¸Á¶Ã¼·Î Á¤ÀÇÇÑ´Ù.
    element data;
    struct ListNode *link;
} ListNode;

element ±¸Á¶Ã¼¿¡´Â data ¸â¹öº¯¼ö°¡ ¾øÀ½!!!

 

 

 

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
#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;
}
 
// Å×½ºÆ® ÇÁ·Î±×·¥
int main(void)
{
    ListNode *head = NULL;
    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);
 
 
    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
#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;
}
 
// Å×½ºÆ® ÇÁ·Î±×·¥
int main(void)
{
    ListNode *head = NULL;
    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);
 
    return 0;
}
cs

  µî·ÏÀÏ : 2020-11-03 [20:05] Á¶È¸ : 667 ´Ù¿î : 360   
 
¡â ÀÌÀü±Û(½Ç½À 9) ¿¬°á ¸®½ºÆ®
¡ä ´ÙÀ½±Û½Ç½À ÇÁ·Î±×·¥ ¿¹)
ÀڷᱸÁ¶ ½Ç½À°Ô½ÃÆÇ
¹øÈ£ ¨Ï Á¦ ¸ñ
[Âü°í] ±³Àç¿¡ ÀÖ´Â ¼Ò½ºÄÚµå
77 (½Ç½À 13) °£´Ü °ÔÀÓ Á¦ÀÛ
76 ¦¦❶ ±â´É ±¸Çö (Ãß°¡)
75    ¦¦❷ (Ãß°¡) ½Ç½À ÇÁ·Î±×·¥ ¿¹)
74 ¨Õ(½Ç½À 12) ¹®ÀÚ¿­ ã±â
73 ¦¦❶ ½Ç½À ÇÁ·Î±×·¥ ¿¹)
72    ¦¦❷ ƯÁ¤ÀÎÀÇ ÀüÈ­¹øÈ£¸¦ ¼öÁ¤ÇÏ´Â ±â´ÉÀ» Ãß°¡ (Ãß°¡)
71       ¦¦❸ (Ãß°¡) ½Ç½À ÇÁ·Î±×·¥ ¿¹)
70 ¨Õ(½Ç½À 11) Æ®¸®
69 ¦¦❶ ½Ç½À ÇÁ·Î±×·¥ ¿¹)
68    ¦¦❷ ¨ÕÂü°í) ¼ö½ÄÀ» ÀÌÁøÆ®¸®·Î º¯È¯ÇÏ´Â ¹æ¹ý
67    ¦¦❷ Æ®¸® ÀڷᱸÁ¶¸¦ ÀÀ¿ëÇÏ¿© ÀΰøÁö´É °áÁ¤ Æ®¸®¸¦ ±¸Çö (Ãß°¡)
66       ¦¦❸ (Ãß°¡) ½Ç½À ÇÁ·Î±×·¥ ¿¹)
65          ¦¦❹ (Ãß°¡) ½Ç½À ÇÁ·Î±×·¥ ¿¹)
64 ¨Õ(½Ç½À 10) ¾ß±¸°ÔÀÓ
63 ¦¦❶ ½Ç½À ÇÁ·Î±×·¥ ¿¹)
62    ¦¦❷ ½Ç½À ÇÁ·Î±×·¥ ¿¹)
61       ¦¦❸ ³­À̵µ¿Í ½ÃµµÈ½¼ö¸¦ Á¶Á¤ÇÒ ¼ö ÀÖµµ·Ï ÇÁ·Î±×·¥À» È®Àå (Ãß°¡)
60          ¦¦❹ (Ãß°¡) ½Ç½À ÇÁ·Î±×·¥ ¿¹)
59 ¨Õ(½Ç½À 9) ¿¬°á ¸®½ºÆ®
58 ¦¦❶ ½Ç½À ÇÁ·Î±×·¥ ¿¹)

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