Skip to main content

Write a C Program to create a stack using an array and perform Push operation , Pop operation

 


#include <stdio.h>

         

#define MAX 50

 

void insert();

void delete();

void display();

int queue_array[MAX];

int rear = - 1;

int front = - 1;

main()

{

    int choice;

    while (1)

    {

        printf("1.Insert element to queue \n");

        printf("2.Delete element from queue \n");

        printf("3.Display all elements of queue \n");

        printf("4.Quit \n");

        printf("Enter your choice : ");

        scanf("%d", &choice);

        switch (choice)

        {

            case 1:

            insert();

            break;

            case 2:

            delete();

            break;

            case 3:

            display();

            break;

            case 4:

          

            exit(1);

            default:

            printf("Wrong choice \n");

        } /* End of switch */

    }

}

 

void insert()

{

    int add_item;

    if (rear == MAX - 1)

    printf("Queue Overflow \n");

    else

    {

        if (front == - 1)

        /*If queue is initially empty */

        front = 0;

        printf("Inset the element in queue : ");

        scanf("%d", &add_item);

        rear = rear + 1;

        queue_array[rear] = add_item;

    }

} /* End of insert() */

 

void delete()

{

    if (front == - 1 || front > rear)

    {

        printf("Queue Underflow \n");

        return ;

    }

    else

    {

        printf("Element deleted from queue is : %d\n", queue_array[front]);

        front = front + 1;

    }

} /* End of delete() */

 

void display()

{

    int i;

    if (front == - 1)

        printf("Queue is empty \n");

    else

    {

        printf("Queue is : \n");

        for (i = front; i <= rear; i++)

            printf("%d ", queue_array[i]);

        printf("\n");

    }

 

}

Comments

Popular posts from this blog

Windows 11 Pro Activation Key

 Windows 11 Pro key: W269N-WFGWX-YVC9B-4J6C9-T83GX Windows 11 Pro N key: MH37W-N47XK-V7XM9-C7227-GCQG9 Windows 11 Pro Workstations key: NRG8B-VKK3Q-CXVCJ-9G2XF-6Q84J Windows 11 Pro Workstations N key: 9FNHH-K3HBT-3W4TD-6383H-6XYWF Windows 11 Pro Education key: 6TP4R-GNPTD-KYYHQ-7B7DP-J447Y Windows 11 Home key: TX9XD-98N7V-6WMQ6-BX7FG-H8Q99 Windows 11 Home N key: 3KHY7-WNT83-DGQKR-F7HPR-844BM Windows 11 Home Home Single Language key: 7HNRX-D7KGG-3K4RQ-4WPJ4-YTDFH Windows 11 Home Country Specific: PVMJN-6DFY6-9CCP6-7BKTT-D3WVR Windows 11 Education key: NW6C2-QMPVW-D7KKK-3GKT6-VCFB2 Windows 11 Education N: 2WH4N-8QGBV-H22JP-CT43Q-MDWWJ Windows 11 Enterprise key: NPPR9-FWDCX-D2C8J-H872K-2YT43 Windows 11 Enterprise N key: DPH2V-TTNVB-4X9Q3-TJR4H-KHJW4 Windows 11 Enterprise G: YYVX9-NTFWV-6MDM3-9PT4T-4M68B Windows 11 Enterprise G N: 44RPN-FTY23-9VTTB-MP9BX-T84FV Windows 11 Enterprise LTSC 2019 key: M7XTQ-FN8P6-TTKYV-9D4CC-J462D Windows 11 Enterprise N LTSC 2019 key: 92NFX-8DJQP-P6BBQ-THF...

Write a C Program for All-Pairs Shortest Paths using Floydd’s Algorithm

  #include<stdio.h> #include<conio.h> int min(int,int); void floyds(int p[10][10],int n) {                 int i,j,k;                 for (k=1;k<=n;k++)                   for (i=1;i<=n;i++)                    for (j=1;j<=n;j++)                     if(i==j)                      p[i][j]=0; else                      p[i][j]=min(p[i][j],p[i][k]+p[k][j]); } i...