Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct node
- {
- int data;
- struct node *next,*prev;
- }NODE;
- NODE *first=NULL,*last=NULL,*temp=NULL;
- int isEmpty(){
- if (first==NULL) return 1;
- else return 0;
- }
- void create(int elem)
- {
- temp=(struct node*)malloc(sizeof(struct node));
- temp->data=elem;
- temp->next=NULL;
- if(first==NULL)
- {
- first=temp;
- last=temp;
- }
- else
- {
- last->next=temp;
- last=temp;
- }
- }
- void display()
- {
- temp=first;
- printf("First->");
- while(temp!=NULL)
- {
- //printf("|%d|%d| --> ",temp->data,temp->next);
- printf("|%d| --> ",temp->data);
- temp=temp->next;
- }
- printf("NULL\n");
- }
- void JeduDvo()
- {
- NODE *p,*q;
- q=first;
- p=first->next;
- while(p!=NULL)
- {
- p->prev=q;
- q=p;
- p=p->next;
- }
- first->prev=NULL;
- }
- void display2()
- {
- //printa unazad da bi videli da li je dvostruka
- temp=last->prev;
- printf("First->|%d|",last->data);
- while(temp!=NULL)
- {
- printf("<--|%d| --> ",temp->data);
- temp=temp->prev;
- }
- printf("NULL\n");
- }
- int main()
- {
- create(1);
- create(2);
- create(3);
- create(4);
- create(5);
- display();
- JeduDvo();
- display2();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement