Queue (Using Link List)

Queue:


//        ******queue using link.cpp
#include<stdio.h>
#include<stdlib.h>
typedef struct data{
        int x;
        struct data *pt;
        }DATA;
       
DATA *head=NULL;
DATA *tail=NULL;

void push()
{
    int i,num;
    DATA *tem;
    tem= (DATA *) malloc ( sizeof(DATA) );
   
    scanf("%d",&num);
    tem->x=num;
    tem->pt=NULL;
   
    if(head==NULL)
                  head=tem;
    else
        tail->pt=tem;

    tail=tem;
}

int pop()
{
        DATA *tem;
        tem=head;
        head=head->pt;

return 0;
}   

void print()
{
    DATA *tem;
    tem=head;
    if(head==NULL)
        printf("Stack Empty\n");
    else
    {

    while(tem !=NULL){
               printf("%d ",tem->x);
            tem=tem->pt;
        }

    printf("\n");
    }

}

int main()
{
    int ch;

    while(1){
        puts("1. Push");
        puts("2. Pop");
        puts("3. Print");
        puts("4. Exit");

        scanf("%d",&ch);
        if(ch==1)
            push();
        else if(ch==2)
            pop();
        else if(ch==3)
            print();
        else
            break;
        }
    return 0;
}

মন্তব্যসমূহ