Storing data in Stack in C

Hey, there today we learn about Storing Technique using Stack Program and Sorting too. Sorting is a technique that sort your virtual Data in Ascending or Descending Order through Storing data in Stack in C.

C Stack program for Sorting Data

#include <stdio.h>

#define STACK_MAX 10

typedef struct

{
int top;
int data[STACK_MAX];
}

Stack;

void push(Stack *s, int item)
{
if(s->top < STACK_MAX)

{
s->top = s->top + 1;
s->data[s->top] = item;

}

else

{
   printf(“Stack is full!/n”);
}
}

int pop(Stack *s)
{
int item;
if(s->top < 0)

{
   printf(“Stack is empty!\n”);
return -1;
}

else

{
    item = s->data[s->top];
s->top–;
   }
    return item;
}

int main()
{
Stack my_stack;
  int item;

    my_stack.top = 0;
  push(&my_stack, 1);
  push(&my_stack, 2);
push(&my_stack, 3);

    item = pop(&my_stack);
   printf(“%d\n”, item);

    item = pop(&my_stack);
    printf(“%d\n”, item);

    item = pop(&my_stack);
    printf(“%d\n”, item);

    return 0;
}

Storing Data in C using Stack

Storing data in Stack in C
Storing data in Stack in C

Stack Program in C

END

Stack program in C++  (clickHere)

Note:- Maybe sometime above code doesn’t get user-friendly output, in codeblock ‘or’ any other EDITOR, All of C & C++ program tested in DOS compiler Turbo C.

Also Read

Types of functions in C    Read Here

I hope you will understand better if you study at M.U, in the exam of M.U you know how important this “Storing data in Stack in C

. So please don’t forget to give your valuable feedback. Go in the comment section and Give us some feedback about it. Storing data in Stack in Cor My website.

Our team check your every Comment per day Because your one feedback helps us in growing Thesmolt

I request you if you have any doubt or question regarding our site, then please don’t hesitate. We always waiting for your Suggestion.

Note:- If you want to Download This article’s in PDF form, then simply go (Top or Bottom of) Right corner and click on the PRINT icon, and it’s saved as a PDF of  Storing data in Stack in C

Sorting Data in C

For further questions, you can contact us Via mail [email protected]  otherwise, Our Help Page and Contact us Page, which is included below. I hope I’ll able to say all the possible ways to reach us. Or Download My Android Application Below Download Button.

thesmolt App

Leave a Reply

x