7 link_t
* list_new(int value
) {
9 link_new
= malloc(sizeof(link_t
));
10 link_new
->value
= value
;
11 link_new
->next
= NULL
;
15 link_t
* list_append(link_t
* head
, int value
) {
18 return head
= list_new(value
);
20 link_t
* head_first
= head
;
21 while (head
->next
!= NULL
) {
24 head
->next
= list_new(value
);
29 link_t
* list_prepend(link_t
* head
, int value
) {
30 link_t
* first_link
= list_new(value
);
32 first_link
->next
= head
;
36 link_t
* list_insert(link_t
* head
, unsigned index
, int value
) {
39 return list_prepend(head
, value
);
40 } else if (index
== list_count(head
)) {
41 return list_append(head
, value
);
43 link_t
* link_insrt
= list_new(value
);
44 link_t
* head_first
= head
;
45 link_t
* head_next
= NULL
;
46 for (unsigned i
= 0; i
< index
-1; i
++) {
49 head_next
= head
->next
;
50 head
->next
= link_insrt
;
52 head
->next
= head_next
;
57 link_t
* list_delete(link_t
* head
, unsigned index
) {
58 link_t
* head_prev
= NULL
;
59 link_t
* head_next
= NULL
;
60 link_t
* head_ret
= NULL
;
64 } else if (index
== 0) {
65 head_next
= head
->next
;
70 link_t
* head_first
= head
;
71 for (unsigned i
= 0; i
< index
-1; i
++) {
76 head_next
= head
->next
;
79 head
->next
= head_next
;
80 head_ret
= head_first
;
82 if (head_ret
!= NULL
) {
89 link_t
* list_concat(link_t
* first
, link_t
* second
) {
90 link_t
* head_first
= first
;
92 while (first
->next
!= NULL
) {
99 link_t
* list_sort(link_t
* head
) {
102 link_t
* head_first
= head
;
106 while (head
->next
!= NULL
) {
107 if (head
->value
> head
->next
->value
) {
109 head
->value
= head
->next
->value
;
110 head
->next
->value
= tmp
;
115 /* Reloop at the beginning of the list until there's is values swaped */
121 unsigned list_count(link_t
* head
) {
124 while (head
!= NULL
) {
131 void list_set(link_t
* head
, unsigned index
, int value
) {
134 while (head
!= NULL
&& count
< index
) {
138 if (head
!= NULL
) { head
->value
= value
; }
141 int list_get(link_t
* head
, unsigned index
) {
144 while (head
!= NULL
&& count
< index
) {
155 void list_clear(link_t
* head
) {
156 link_t
* next_link
= NULL
;
158 while (head
!= NULL
) {
159 next_link
= head
->next
;
165 void list_display_values(link_t
* head
) {
168 printf("------Begin------\n");
169 while (head
!= NULL
) {
170 printf("value at [%d]=%d\n", i
, head
->value
);
174 printf("------End------\n");