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>
- typedef struct broj * br;
- struct broj
- {
- int b;
- br next;
- };
- void dodaj1(br p1)
- {
- printf("dodaj elemente u prvu listu\n");
- br temp;
- temp=(br)malloc(sizeof(struct broj));
- printf("Unesite broj :");
- scanf("%d",&temp->b );
- temp->next=p1->next;
- p1->next=temp;
- }
- void dodaj2(br p2)
- {
- printf("dodaj elemente u drugu listu\n");
- br temp;
- temp=(br)malloc(sizeof(struct broj));
- printf("Unesite broj :");
- scanf("%d",&temp->b );
- temp->next=p2->next;
- p2->next=temp;
- }
- void ispis1(br p1)
- {
- while(p1!=NULL)
- {
- printf("%d \n",p1->b);
- p1=p1->next;
- }
- }
- void ispis2(br p2)
- {
- while(p2!=NULL)
- {
- printf("%d \n",p2->b);
- p2=p2->next;
- }
- }
- void presjek(br p1,br p2,br p)
- {
- br temp;
- while(p1!=NULL && p2!=NULL)
- {
- if(p1->b == p2->b)
- {
- temp=(br)malloc(sizeof(struct broj));
- temp->b=p1->b;
- temp->next=p->next;
- p->next=temp;
- p1=p1->next;
- p2=p2->next;
- p=p->next;
- }
- else if(p2->b < p1->b)
- {
- p2=p2->next;
- }
- else
- {
- p1=p1->next;
- }
- }
- }
- void ispisp(br p)
- {
- printf("\n");
- p = p->next;
- while(p != NULL)
- {
- printf("\t%d", p->b);
- p = p->next;
- }
- printf("\n");
- }
- int main()
- {
- struct broj p1;
- struct broj p2;
- p1.next=NULL;
- p2.next=NULL;
- struct broj p;
- p.next=NULL;
- char izbor=0;
- while(izbor!='k')
- {
- printf("unesite A za dodaj u prvu,B za dodaj u drugu,C za ispis prve,D za ispis druge,E za uniju:\n");
- scanf(" %c", &izbor);
- switch(izbor)
- {
- case 'a':
- dodaj1(&p1);
- break;
- case 'b':
- dodaj2(&p2);
- break;
- case 'c':
- ispis1(p1.next);
- break;
- case 'd':
- ispis2(p2.next);
- break;
- case 'e':
- presjek(&p1,&p2,&p);
- break;
- case 'f':
- ispisp(p.next);
- break;
- case 'k':
- printf("Kraj");
- break;
- default:
- printf("pogresan odabir\n");
- }
- }
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment