Advertisement
ramytamer

QLS

May 7th, 2014
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.69 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct node{
  5.     int data;
  6.     struct node *next;
  7.     struct node *pre;
  8. }node;
  9.  
  10. typedef struct {
  11.     node *head;
  12.     node *tail;
  13. }Queue;
  14.  
  15. void intiallize (Queue *q){
  16.     q->head = q->tail = NULL;
  17. }
  18.  
  19. int isempty(Queue *q){
  20.     return q->head==NULL;
  21. }
  22.  
  23. void add_in_front(Queue *q, int x){
  24.     node *p = (node*) malloc(sizeof(node));
  25.     if (!isempty(q)){
  26.         p->data = x;
  27.         p->next = q->head;
  28.         p->pre = NULL;
  29.        (q->tail)->next=p;
  30.     }else{
  31.         p->data = x;
  32.         p->next = NULL;
  33.         p->pre = NULL;
  34.         (q->tail)->next=p;
  35.     }
  36. }
  37.  
  38.  
  39.  
  40. int main()
  41. {
  42.     Queue q; intiallize(&q);
  43.     printf("Hello world!\n");
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement