Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <stdio.h>
- #define SIZE 100
- struct node
- {
- char info[SIZE];
- struct node *next, *prev;
- };
- void create(struct node **lista,char data[])
- {
- struct node *temp;
- temp = (struct node *)malloc(sizeof(struct node));
- if (*lista == NULL)
- {
- strcpy(temp->info,data);
- temp->next=NULL;
- temp->prev=NULL;
- *lista=temp;
- }
- }
- void print_list_in_both_directions(struct node *list_pointer)
- {
- struct node *backward_pointer = NULL;
- puts("");
- puts("normal direction:");
- while (list_pointer)
- {
- backward_pointer = list_pointer;
- printf("%s", list_pointer->info);
- list_pointer = list_pointer->next;
- }
- puts("");
- puts("backward direction:");
- while (backward_pointer)
- {
- printf("%s", backward_pointer->info);
- backward_pointer = backward_pointer->prev;
- }
- }
- void insert_end(struct node **lista,char data[])
- {
- struct node *ptr, *tempnode;
- ptr = *lista;
- if(*lista==NULL)
- {
- create(lista,data);
- }
- else
- {
- while(ptr->next!=NULL)
- ptr=ptr->next;
- tempnode=(struct node *)malloc(sizeof(struct node));
- strcpy(tempnode->info,data);
- tempnode->next=NULL;
- tempnode->prev=ptr;
- ptr->next=tempnode;
- }
- }
- int main()
- {
- struct node *lista=NULL;
- char data[SIZE];
- char str[]="koniec\n";
- do
- {
- printf("wpisz slowo ");
- fgets(data, SIZE, stdin);
- insert_end(&lista,data);
- }
- while(strcmp(data,str)!=0);
- print_list_in_both_directions(lista);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement