Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef struct dl_list_t dl_list_t;
- struct dl_list_t
- {
- char *str; //yes, this is just a string since you're porting to java
- dl_list_t *next, *prev;
- };
- dl_list_t *dl_list_create()
- {
- dl_list_t *tmp = malloc(sizeof(dl_list_t));
- if(tmp == NULL)
- return NULL;
- memset(tmp, 0, sizeof(dl_list_t));
- return tmp;
- }
- dl_list_t *dl_list_free(dl_list_t *head)
- {
- while(head->prev != NULL)
- head=head->prev;
- while(head != NULL)
- {
- dl_list_t *tmp = head;
- head=head->next;
- free(tmp->str);
- free(tmp);
- }
- return head;
- }
- dl_list_t *dl_list_insert(dl_list_t *dl_list, char *stri)
- {
- if(dl_list == NULL)
- return NULL;
- dl_list_t *tmp = dl_list;
- if(tmp->next != NULL)
- tmp=tmp->next;
- if(tmp->str == NULL)
- {
- tmp->str = malloc(strlen(cats)+1);
- strcpy(tmp->str, cats);
- }
- else if(strcmp(tmp->str, cats) != 0)
- {
- tmp->next = dl_list_create();
- if(tmp->next == NULL)
- return NULL;
- tmp->next->prev = tmp;
- tmp = tmp->next;
- tmp->str = malloc(strlen(cats)+1);
- strcpy(tmp->str, cats);
- }
- return tmp;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement