Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

creation and uses of array, Schemes and Mind Maps of Computer Science

it gives the brief detail of array structure,creation on it

Typology: Schemes and Mind Maps

2022/2023

Uploaded on 01/04/2023

Mathivanans
Mathivanans 🇮🇳

3 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Program
#include<stdio.h>
#include<stdlib.h>
int stack[100],i,input,len,init,top=-1;
void push();
void pop();
void peek();
void display();
void quit();
void main()
{
printf("\nEnter Total length of Stack:");
scanf("%d",&len);
printf("\nHow many element do you want to insert:");
scanf("%d",&init);
for(i=0;i<init;i++)
{
printf("\nEnter the Element:");
scanf("%d",&input);
top+=1;
pf3
pf4
pf5

Partial preview of the text

Download creation and uses of array and more Schemes and Mind Maps Computer Science in PDF only on Docsity!

Program #include<stdio.h> #include<stdlib.h> int stack[100],i,input,len,init,top=-1; void push(); void pop(); void peek(); void display(); void quit(); void main() { printf("\nEnter Total length of Stack:"); scanf("%d",&len); printf("\nHow many element do you want to insert:"); scanf("%d",&init); for(i=0;i<init;i++) { printf("\nEnter the Element:"); scanf("%d",&input); top+=1;

stack[top]=input; } printf("\n1:Push\t2:Pop\t3:Peek\t4:display\t5:Quit"); while(1){

Enter a number to perform operation: Inserted Successfully

scanf("%d",&input); switch(input) { case 1: push(); break; case 2: pop(); break; case 3: peek(); break; case 4: display(); break; case 5: quit(); break;

void peek(){ if(top == -1){ printf("\nStack is empty");} else{ printf("\nPeek element is %d",stack[top]);} } void display(){ if(top == -1) printf("\nStack is empty"); else { printf("\nElements in Stack:"); for(i=0;i<=top;i++){ printf("%d ",stack[i]);} printf("\n"); } } void quit(){ exit(0); }

Output

Enter the Element: Enter the Element: Enter a number to perform operation:

  • Enter Total length of Stack:
  • How many element do you want to insert:
  • Enter the Element:
  • Enter the Element:
  • Enter the Element:
  • Enter a number to perform operation: 1:Push 2:Pop 3:Peek 4:display 5:Quit
  • Peek element is
  • Enter a number to perform operation:
  • Elements in Stack:1
  • Enter a number to perform operation:
  • Enter the Element:
  • Enter a number to perform operation: Inserted Successfully