Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct tnode
- {
- int value;
- struct tnode *next;
- } tnode;
- tnode *add(tnode *list_1, tnode *list_2)
- {
- tnode *hold=list_1;
- if (hold==NULL)
- {
- list_2->next=list_2;
- return list_2;
- }
- else
- {
- tnode *current_1=list_1;
- while(current_1->next!=hold)
- {
- current_1=current_1->next;
- }
- current_1->next=list_2;
- list_2->next=hold;
- return hold;
- }
- }
- void wypisz_cycle ( tnode *list)
- {
- if (list == NULL)
- {
- printf ("PUSTA \n");
- return;
- }
- tnode * wsk = list;
- do
- {
- printf ("[%d] ", list->value);
- list = list->next;
- }
- while (list != wsk);
- return;
- }
- void wypisz(tnode *list)
- {
- if (list==NULL)
- return;
- while (list!=NULL)
- {
- printf("[%d]->",list->value);
- list=list->next;
- }
- puts("\n");
- }
- void usun(tnode **list)
- {
- if ((*list)==NULL)
- return;
- tnode *head=*list;
- tnode *last=*list;
- while (last->next!=head)
- last=last->next;
- last->next=NULL;
- while ((head->value)%2==0 && head!=NULL)
- {
- tnode *tmp=head;
- head=head->next;
- free(tmp);
- }
- *list=head;
- if(head==NULL)
- {
- return;
- }
- tnode *current=*list;
- tnode *prev=*list;
- current=current->next;
- while(current!=NULL)
- {
- if((current->value)%2==0)
- {
- current=current->next;
- free(prev->next);
- prev->next=current;
- }
- else
- {
- current=current->next;
- prev=prev->next;
- }
- }
- }
- int main()
- {
- tnode *head=NULL;
- tnode *one=malloc(sizeof(tnode));
- tnode *two=malloc(sizeof(tnode));
- tnode *three=malloc(sizeof(tnode));
- tnode *four=malloc(sizeof(tnode));
- one->value=2;
- one->next=NULL;
- two->value=3;
- two->next=NULL;
- three->value=4;
- three->next=NULL;
- four->value=5;
- four->next=NULL;
- head=add(head,one);
- head=add(head,two);
- head=add(head,three);
- head=add(head,four);
- puts("Pierwsza lista:");
- wypisz_cycle(head);
- printf("lista1 = %d, lista2 = %d\n",head->value,head->next->value);
- usun(&head);
- //wypisz_cycle(head);
- wypisz(head);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement