In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
In this issue, the editor will bring you how to understand the stack in the data structure of C language. the article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
The main contents of chained implementation of stack
(1) the stack consists of seven elements, which in turn are 67 bottom 3 and 88 pointer, respectively. The stack is created by tail insertion method, and two pointers are set for the stack, one pointer and one top pointer.
(2) enter the stack function push, which completes the function of inserting elements into the stack. Using the push function, insert the number-9 into the stack and traverse the elements in the stack.
(3) the stack function pop, which completes the function of deleting elements from the stack. Using the pop function, delete the three elements in the stack and traverse the stack.
(4) function length to find out the number of elements in the stack at this time.
Code implementation: # include#includestruct node {int date; struct node * next;}; struct stack {struct node * bottom; struct node * top;} s * struct stack * creat (struct stack * s); / / create stack void push (struct stack * sline int e); / / stack void print (struct stack * s); / / printout void pop (struct stack * s) / / output stack void length (struct stack * s); / / output stack length int main () {struct stack * stack (s); push (SMagne67); push (sMage3); push (sMage88); push (sMage6); push (sMage1); push (sMagol 7); push (sMage0) Printf ("initial stack elements are:"); print (s); printf ("\ n"); printf ("\ n"); push (after inserting elements:); printf ("after inserting elements:"); print (s); printf ("\ n"); printf ("\ n"); pop (s); printf ("after deleting elements:") Print (s); printf ("\ n"); printf ("\ n"); length (s); return 0;} struct stack * creat (struct stack * s) {s = (struct stack *) malloc (sizeof (struct stack)); s-> bottom=s- > top= (struct node *) malloc (sizeof (struct node)); s-> top- > next=NULL; s > bottom- > next=NULL; return s } void push (struct stack * spenint e) / / into the stack {struct node * p; p = (struct node *) malloc (sizeof (struct node)); p-> date=e; p-> next=NULL; s-> top- > next=p; s-> top=p;} void pop (struct stack * s) / / out of the stack {struct node * pjingq; pads-> bottom; while (p-> nextstamp null) {qroomp Pairp-> next;} Q-> next=NULL; s-> top=q;} void print (struct stack * s) / / printout {struct node * p = s-> bottom- > next; while (pumped null) {printf ("% 4d", p-> date); pairp-> next }} void length (struct stack * s) / / Compute length {struct node * packs-> bottom- > next; int iTuno; while (packs null) {iTunes; packs-> next;} printf ("stack length at this time:% 4d", I) } above is how to understand the stack in the C language data structure shared by the editor. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.