Stack sequential storage and basic implementation

Source: Internet
Author: User
# Include <iostream> # include <cstring> # include <cstdlib> # define maxsize 1000 using namespace STD; // ordered structure typedef struct {int data [maxsize]; int top ;} sqstack; // initialize the stack void initstack (sqstack * & S) {S = new sqstack; s-> Top =-1; // empty stack} void clearstack (sqstack * & S) {Delete s;} // calculate the stack length int stacklength (sqstack * s) {return (S-> top + 1);} // judge whether the stack is empty int stackempty (sqstack * s) {return (S-> Top =-1 );} // int push (sqstack * & S, int e) {If (S-> Top = maxsize-1) // when the stack is full, stack Overflow return 0; s-> top ++; s-> data [S-> top] = E; // insert e into Stack top return 1 ;} // out-of-stack int POP (sqstack * & S, int e) {If (S-> Top =-1) // In the case of empty stacks, the off-Stack Overflow return 0; E = s-> data [S-> top]; S-> top --; return 1 ;}

 

Stack sequential storage and basic implementation

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.