Thread: How to add data to head and delete from tail

  1. #1
    Registered User
    Join Date
    Jul 2018
    Posts
    79

    How to add data to head and delete from tail

    How to create fifo queue ?

    I made this attempt

    Code:
    #include<stdio.h>
    #include<stdlib.h> 
        
    struct Node  
    { 
      int data; 
      struct Node *next; 
    }; 
      int main() 
    { 
      struct Node* Head = NULL; 
      struct Node* Tail = NULL; 
     
      Head  = (struct Node*)malloc(sizeof(struct Node));  
      Tail = (struct Node*)malloc(sizeof(struct Node)); 
     
      Head->data = 1; 
      head->next = Tail; 
             
      return 0; 
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,662
    Well you make something like this.
    Code:
    struct Queue {
        struct Node* Head;
        struct Node* Tail;
    };
    
    void initQueue( struct Queue * )
    
    void pushQueue( struct Queue *, Node *)
    
    Node *popQueue( struct Queue *)
    Over to you to fill in some functionality.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. "insert sort with head and tail pointers"
    By noway2 in forum C Programming
    Replies: 2
    Last Post: 10-24-2011, 10:18 PM
  2. LVM_INSERTITEM I cannot make head or tail of it.
    By punkywow in forum C++ Programming
    Replies: 1
    Last Post: 10-03-2009, 07:19 AM
  3. joining head to tail
    By m37h0d in forum C++ Programming
    Replies: 0
    Last Post: 04-07-2009, 12:47 PM
  4. Another List Q - Seg fault on head-tail list
    By JimpsEd in forum C Programming
    Replies: 11
    Last Post: 05-10-2006, 12:53 AM
  5. add-delete data
    By mufanz in forum C++ Programming
    Replies: 3
    Last Post: 04-18-2006, 10:49 AM

Tags for this Thread