Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- typedef struct _strList {
- char *str;
- struct _strList *next;
- } strList;
- typedef struct _List {
- strList *begin;
- strList *end;
- } List;
- strList *list_insert(List *lst, char *s) {
- strList *new_cell = (strList*) malloc(sizeof(strList));
- new_cell->str = strdup(s);
- new_cell->next = lst->begin;
- lst->begin = new_cell;
- if(list->end == NULL)
- lst->end = new_cell;
- return lst;
- }
- strList *list_append(strList *lst, char *s) {
- strList *new_cell = (strList*) malloc(sizeof(strList));
- new_cell->str = strdup(s);
- new_cell->next = NULL;
- if (lst) {
- strList *aux;
- for ( aux = lst ; aux->next ; aux = aux->next ) {}
- aux->next = new_cell;
- } else {
- lst = new_cell;
- }
- return lst;
- }
- void show_list(List *lst) {
- strList *aux = lst->begin;
- for( ; aux ; aux = aux->next){
- printf("%s\n", aux->str);
- }
- }
- int main() {
- List *lst = (List*) malloc(sizeof(List));
- lst->begin = lst->end = NULL;
- lst = list_insert(lst, "Ola");
- lst = list_insert(lst, "Bah");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement