2e0352de109dfede2612bc175e0a6e9ab85c4c63
5 link_t
* list_new(int value
) {
7 link_new
= malloc(sizeof(link_t
));
8 link_new
->value
= value
;
13 link_t
* list_append(link_t
* head
, int value
) {
16 return head
= list_new(value
);
18 link_t
* head_first
= head
;
19 while (head
->next
!= NULL
) {
22 head
->next
= list_new(value
);
27 link_t
* list_prepend(link_t
* head
, int value
) {
28 link_t
* first_link
= list_new(value
);
30 first_link
->next
= head
;
34 link_t
* list_insert(link_t
* head
, unsigned index
, int value
) {
35 link_t
* link_insrt
= list_new(value
);
36 link_t
* head_first
= head
;
37 //link_t* head_prev = NULL;
38 link_t
* head_next
= NULL
;
40 for (unsigned i
= 0; i
< index
; i
++) {
44 head
->next
= link_insrt
;
45 head_next
= head
->next
;
47 head
->next
= head_next
;
51 link_t
* list_delete(link_t
* head
, unsigned index
) {
52 link_t
* head_first
= head
;
53 link_t
* head_prev
= NULL
;
54 link_t
* head_next
= NULL
;
57 head_next
= head
->next
;
62 for (unsigned i
= 0; i
< index
-1; i
++) {
67 head_next
= head
->next
;
70 head
->next
= head_next
;
75 unsigned list_count(link_t
* head
) {
78 while (head
!= NULL
) {
85 void list_set(link_t
* head
, unsigned index
, int value
) {
88 while (head
!= NULL
&& count
< index
) {
92 if (head
!= NULL
) { head
->value
= value
; }
95 int list_get(link_t
* head
, unsigned index
) {
98 while (head
!= NULL
&& count
< index
) {
109 void list_clear(link_t
* link
) {
110 link_t
* next_link
= NULL
;
112 while (link
!= NULL
) {
113 next_link
= link
->next
;