Compare commits
2 Commits
c73be4c21c
...
16470f2592
Author | SHA1 | Date | |
---|---|---|---|
16470f2592
|
|||
db42c21754
|
10
ds.c
10
ds.c
@ -67,7 +67,7 @@ void
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = -1, cur = *ll;; i++, cur = cur->next) {
|
for (i = -1, cur = *ll; cur; i++, cur = cur->next) {
|
||||||
if (i + 1 == idx) {
|
if (i + 1 == idx) {
|
||||||
if (idx == 0) {
|
if (idx == 0) {
|
||||||
rm = cur;
|
rm = cur;
|
||||||
@ -86,6 +86,10 @@ void
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!rm) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
data = rm->data;
|
data = rm->data;
|
||||||
free(rm);
|
free(rm);
|
||||||
return data;
|
return data;
|
||||||
@ -127,6 +131,10 @@ void
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!rm) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
data = rm->data;
|
data = rm->data;
|
||||||
free(rm);
|
free(rm);
|
||||||
return data;
|
return data;
|
||||||
|
14
ds.h
14
ds.h
@ -1,14 +1,14 @@
|
|||||||
#ifndef _DS_LOADED
|
#ifndef DS_H
|
||||||
#define _DS_LOADED
|
#define DS_H
|
||||||
|
|
||||||
typedef struct _sll {
|
typedef struct _ds_sll {
|
||||||
struct _sll *next;
|
struct _ds_sll *next;
|
||||||
void *data;
|
void *data;
|
||||||
} ds_sll_t;
|
} ds_sll_t;
|
||||||
|
|
||||||
typedef struct _dll {
|
typedef struct _ds_dll {
|
||||||
struct _dll *next;
|
struct _ds_dll *next;
|
||||||
struct _dll *prev;
|
struct _ds_dll *prev;
|
||||||
void *data;
|
void *data;
|
||||||
} ds_dll_t;
|
} ds_dll_t;
|
||||||
|
|
||||||
|
1
test.c
1
test.c
@ -17,6 +17,7 @@ main(int argc, char *argv[])
|
|||||||
ds_ll_foreach(ds_sll_t, ll) {
|
ds_ll_foreach(ds_sll_t, ll) {
|
||||||
puts(cur->data);
|
puts(cur->data);
|
||||||
}
|
}
|
||||||
|
ds_sll_remove(&ll, 1234);
|
||||||
char *pa = ds_sll_remove(&ll, 0); // [ "two" ]
|
char *pa = ds_sll_remove(&ll, 0); // [ "two" ]
|
||||||
char *pb = ds_sll_remove(&ll, 0); // [ ]
|
char *pb = ds_sll_remove(&ll, 0); // [ ]
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user