Data structure note 1 sequence stack

Source: Internet
Author: User

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#define MAX 100
typedef struct{
int Data[max];
int top;
}stack;
Stack s;
Initialization succeeded 1
int Initstack (Stack s) {
S.top=-1;
return 1;
}
Non-empty 1
int Stackempty (Stack s) {
if ( -1==s.top)
return 0;
return 1;
}
Under 1
int Stackfull (Stack s) {
if (max-1==s.top)
return 0;
return 1;
}
For length success 1 output length
int Stacklength (Stack s) {
printf ("Length%d", s.top+1);
return 1;
}
Access stack top returns 1 output elements
int GetTop (Stack s,int *e) {
E=s.data;
printf ("Stack top element is%d", *e);
return 1;
}
Into the Stack success 1
int Push (Stack s,int e) {
++s.top;
S.data[s.top]=e;
printf ("Into the stack success!") \ n ");
return 0;
}
Out of Stack success 1
int Pop (Stack s,int *e) {
*e=s.data[s.top];
s.top--;
return 1;
}
int main () {
int i,e,*e1,*e2;
Stack L;
printf ("Now start the operation of the station!\n");
if (1!=initstack (L)) {
printf ("Initialization failed, press any key to exit!\n");
Getch ();
Exit (0);
}
if (1!=stackempty (L)) {
printf ("The space on the stack is empty!") \ n ");
Exit (0);
}
printf ("Do you want to do a stack operation?") 1-yes ");
scanf ("%d", &i);
if (1==i) {
Loop
printf ("Enter the element you want to stack into:");
scanf ("%d", &e);
if (1!=stackfull (L)) {
printf ("Stack space is full!") \ n ");
printf ("Do you want to do a stack operation 1 or access top operation 2?") \ n ");
printf ("Please enter your choice:");
scanf ("%d", &i);
if (i==1)
Goto Pop;
else if (i==2)
Goto GetTop;
else{
printf ("The operation failed, press any key to exit!") \ n ");
Getch ();
Exit (0);
}
}
else{
Push (l,e);
printf ("Do you want to continue into the stack?" 1-yes ");
scanf ("%d", &i);
if (i==1)
Goto Loop;
}
}
else{
printf ("Do you want to do a stack operation 1 or access top operation 2?") \ n ");
printf ("Please enter your choice:");
scanf ("%d", &i);
if (i==1)
Goto Pop;
else if (i==2)
Goto GetTop;
else{
printf ("The operation failed, press any key to exit!") \ n ");
Getch ();
Exit (0);
}
}
Pop
Pop (L,E1);
printf ("Do you want to continue with the stack operation?") 1 is ");
scanf ("%d", &i);
if (1==i)
Goto Pop;
GetTop
GetTop (L,E2);
printf ("The operation of the sequential stack has ended!");
return 0;
}

Data structure note 1 sequence stack

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.