Write a program to show the PUSH method in Data Structure

#include<stdio.h>
#include<conio.h>
void main()
{
    int a[10],max=10, i, n, tos , item;
    printf("enter no. of elements=");
    scanf("%d",&n);
    printf("enter array elements\n");
   
    for(i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    tos=n;
    if(tos>=max)
    {
        printf("overflow");
        exit;
   
    }
    else
        {
        printf("enter item to be inserted=");
        scanf("%d",&item);
        tos=tos+1;
        a[tos]=item;
        printf("new stack\n");
        for(i=1;i<=tos;i++)
        {
            printf("%d\n",a[i]);
        }
        }
   
       
        }

Comments

Popular posts from this blog

Write a program to add two number using inline function in C++?

Traversing of elements program with algorithm and Flowchart