Talk C Chestnut Bar (16th: C-language example-stack one)

Source: Internet
Author: User


Crossing, everyone, from today onwards, we talk about the large-scale couplet science fiction: C Chestnut, that is, C language examples. Gossip Hugh,

Words return to the positive turn. Let's talk C chestnuts together!


Crossing, the last time we talked about the example of a doubly linked list, this time we say the example is: stack.


What is a stack? We have heard of the Dragon Inn, which inn are you? I have not said that there are already Sir under the Taiwan question. Crossing, the stack is

Like the list we mentioned in the previous few, it's also an abstract data structure for storing data. Because we are more abstract, we

It's a real-life example to illustrate.

When we go on a trip, we usually take a suitcase to store our belongings, such as clothes, shoes, computers, cameras, etc. Before we leave, we will

These things are placed in the trunk, first of all the items that are not easily crushed are placed at the bottom of the box, such as clothes. And put things that are easy to crush.

To the top, such as computers and cameras. When we arrive at our destination, we take out the items in the suitcase. First, take out the computer on the box.

And the camera, and finally took out the clothes on the bottom of the box. Let's see, the order in which items are taken and the order in which they are stored is exactly the opposite. Finally put

Easy-to-crush items, such as computers and cameras, are first taken out, and the items that are first put in are not easily crushed. This line

The box is like a stack of data, the contents of the box as data, from the box to take items like operating data, take items to take first

The last item to be stored, the operation data must first be put into the data on the stack. This means that the data that was first stored in the stack is finally taken out.

This is the characteristics of the stack: Advanced back out.


Crossing, like linked lists, stacks are implemented in two ways: sequential storage and chained storage. We will give examples to illustrate the difference. Stack has two base

This operation: out of the stack and into the stack. In the stack is to put the data into the stack, the stack is to take the data out of the stack. Both into the stack and out of the stack

Operation to meet the stack "advanced out" characteristics.


Crossing, the text does not write code, the detailed code put in my resources, you can click the link to download the use. About the Code

There are some places to be aware of and everyone to say:

  • The sequential storage of stacks is implemented by a global array, and the stack size is the length of the array, which can be defined by itself.
  • In the stack to confirm whether the stack has been manufactoring, or there will be overflow. I put a little more space in the code to avoid overflow.
  • When you are out of the stack, make sure the stack is empty or there will be overflow. I can avoid overflow by putting more than one variable in the code.


You crossing, we're going to talk about the stack here. I want to know what the following example, and listen to tell.


Talk C Chestnut Bar (16th: C-language example-stack one)

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.