Advertisement
Guest User

Jednostruka2Dvostruka

a guest
Jan 18th, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.31 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. typedef struct node
  4. {
  5.     int data;
  6.     struct node *next,*prev;
  7. }NODE;
  8. NODE *first=NULL,*last=NULL,*temp=NULL;
  9. int isEmpty(){
  10.     if (first==NULL) return 1;
  11.     else return 0;
  12. }
  13. void create(int elem)
  14. {
  15.     temp=(struct node*)malloc(sizeof(struct node));
  16.     temp->data=elem;
  17.     temp->next=NULL;
  18.     if(first==NULL)
  19.     {
  20.         first=temp;
  21.         last=temp;
  22.     }
  23.     else
  24.     {
  25.         last->next=temp;
  26.         last=temp;
  27.     }
  28.  
  29. }
  30. void display()
  31. {
  32.     temp=first;
  33.     printf("First->");
  34.     while(temp!=NULL)
  35.     {
  36.     //printf("|%d|%d| --> ",temp->data,temp->next);
  37.     printf("|%d| --> ",temp->data);
  38.     temp=temp->next;
  39.     }
  40.       printf("NULL\n");
  41. }
  42. void JeduDvo()
  43. {
  44.     NODE *p,*q;
  45.     q=first;
  46.     p=first->next;
  47.      while(p!=NULL)
  48.     {
  49.         p->prev=q;
  50.         q=p;
  51.         p=p->next;
  52.     }
  53.     first->prev=NULL;
  54. }
  55. void display2()
  56. {
  57.     //printa unazad da bi videli da li je dvostruka
  58.     temp=last->prev;
  59.     printf("First->|%d|",last->data);
  60.     while(temp!=NULL)
  61.     {
  62.     printf("<--|%d| --> ",temp->data);
  63.     temp=temp->prev;
  64.     }
  65.       printf("NULL\n");
  66. }
  67. int main()
  68. {
  69.     create(1);
  70.     create(2);
  71.     create(3);
  72.     create(4);
  73.     create(5);
  74.     display();
  75.     JeduDvo();
  76.     display2();
  77.     return 0;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement