Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct element{
- struct element *prev;
- struct element *next;
- char *text;
- };
- typedef struct element linked_list;
- linked_list empty_linked_list(){
- linked_list kopf = {NULL,NULL,NULL};//malloc(sizeof(linked_list));
- return kopf;
- }
- int append(linked_list *liste,char* text){
- linked_list *ele = malloc(sizeof(linked_list));
- if(ele != NULL){
- ele->text = text;
- if(liste->next == NULL){//liste = leer
- liste->prev = ele;
- liste->next = ele;
- //return 1;
- }else{
- liste->prev = ele; //letzte element
- ele->prev = liste;//letzte element in der Liste
- //return 11;
- }
- return 1;
- }else{
- return 0;
- }
- }
- void worka(char* t){
- printf("%s\n",t);
- }
- void visit_all(linked_list *liste, void (*work)(char* t)){
- while(liste->next != NULL){
- work(liste->text);
- //printf("%s\n",liste->text);
- liste = liste->next;
- }
- }
- int main(){
- linked_list li = empty_linked_list();
- char *bla = "hallo";
- char *bla2 = "Welt";
- printf("%d\n", append(&li,bla));
- printf("%d\n", append(&li,bla));
- // printf("%d\n", insert(&li,bla2,2));
- visit_all(&li,&worka);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement