The chain storage structure of the stack of the big talk data structure

Source: Internet
Author: User

#include <iostream>//#include <time.h>//#include <stdlib.h>using namespace std; #define OK 1#define TRUE 1#define FALSE 0#define ERROR 0typedef int status;//Returns the status value typedef int ELEMTYPE;//node data type//per node structure typedef struct Stacknode{elemtype the data;//node's data stacknodeptr next;//refers to the pointer to a node down.} STACKNODE,*STACKNODEPTR;//TOP data structure typedef struct LINLSTACK{STACKNODEPTR top;//pointer to the top element of the stack. int count;//number of elements} linlstack;//into stack operation//value e pressed into stack L status Push_stack (Linlstack *l,elemtype e) {stacknodeptr p;//define a pointer to node p= (stacknodeptr) malloc (Stacknode);//Open dynamic memory p->next=l->top;//the pointer of the node to the original stack-top element p->data=e;//assigns the value of E to the current top-of-stack element l->top =p;//the top pointer to the current stack top element l->count++;//The value of the Count plus a return OK;} Out of stack operation//the stack top element in the stack L pops up to E in status Pop_stack (Linlstack *l,elemtype &e) {if (l->count==0)//If stack is empty the stack returns an error indicating return errors; e=l->top->data;//the data for the top element of the stack to estacknodeptr p;//Define a node pointer p=l->top;//pointer to the original top element of the stack l->top=l->top-> next;//the original stack top element below the address of an element to the topl->count--;//count minus one free (p);//The element that pops up the stack frees the memory space return OK; int main () {sysTEM ("pause"); return 1;} 

  

The chain storage structure of the stack of the 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.