Chain Stack -- (97 pages of big talk data structure)

Source: Internet
Author: User
// Implementation of the chain stack-big talk Data Structure 99 pages # include <iostream> using namespace STD; // The chain node defines typedef struct stacknode {int data; struct stacknode * Next ;} stacknode, * linkstackptr; // defines the chain stack, header pointer and length struct linkstack {linkstackptr top; int count ;};

// Initialization
Void initstack (linkstack * l ){
L-> Top = NULL;
L-> COUNT = 0;
}

// Int push (linkstack * l, int e) {linkstackptr S = new stacknode; // apply for memory S-> DATA = e for the new element; // put the data to be inserted into the data S-> next = L-> top of the applied node; // put the data in the top node into the next L-> Top = s; // assign s to top L-> count ++; // The number of data plus a return 0; // normal termination} int POP (linkstack * l) {linkstackptr P; if (L-> Top = NULL) // determines whether it is null. If it is null, the return-1; int e; E = L-> top-> data; // top refers to the top data of the stack P = L-> top; // top is assigned to p l-> Top = L-> top-> next; // big case data structure 99 pages free (p); // release p l-> count --; // subtract one return E from the data; // return the output stack data}
// Destroy the stack
Void destroystack (linkstack * l) {linkstackptr Q; while (L-> count) {q = L-> top-> next; delete L-> top; l-> Top = Q; L-> count --;} cout <"destroyed successfully" <Endl ;}
 

 

void main(){    LinkStack a;
InitStack(&a); Push(&a,3); Push(&a,4); Push(&a,5); cout<<Pop(&a)<<endl; cout<<Pop(&a)<<endl; cout<<Pop(&a)<<endl;}

Chain Stack -- (97 pages of big talk data structure)

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.