Concepts essential to understanding the essence of a set 02-stack, 02-Stack

Source: Internet
Author: User

Concepts essential to understanding the essence of a set 02-stack, 02-Stack

In "concepts that must be known about the essence of a set-linked list", we understand the concepts and types of linked lists and simulate a one-way linked list. In this article, the stack is a constrained linked list, which can only receive new nodes and release nodes at the top of the stack.

 

The main operations of a stack Are stack pressure and stack exit. Stack stress is to place the new node on the top of the stack. The output stack extracts a node from the top of the stack and returns the data items of the new pop-up node. Stack is also known as the data structure of the Back-to-first-out mode.

 

Next, in the previous article, write a List-derived class to simulate the stack pressure and output stack.

namespace LinkedListLibrary
{
    public class StackInheritance : List
    {
        public StackInheritance() : base("stack"){}
        public void Push(object dataValue)
        {
            InsertAtFront(dataValue);
        }
        public object Pop()
        {
            return RemoveFromFront();
        }
    }
}

 

Client call.

        public static void Main(string[] args)
        {
            StackInheritance stack = new StackInheritance();
            bool aBoolean = true;
            char aChar = 'a';
            int anInt = 12;
            string aStr = "hello";
            stack.Push(aBoolean);
            stack.Display();
            stack.Push(aChar);
            stack.Display();
            stack.Push(anInt);
            stack.Display();
            stack.Push(aStr);
            stack.Display();
            try
            {
                while (true)
                {
                    object removedObject = stack.Pop();
Console. WriteLine (removedObject + "popped up ~~ ");
                    stack.Display();
                }
            }
            catch (EmptyListException emptyListException)
            {                
                Console.Error.WriteLine(emptyListException.StackTrace);
            }
            Console.ReadKey();
        }

 

 

References:

Visual C #2008 University tutorial-(Third edition)

 

The series "concepts that must be known to understand the essence of a set" includes:

Concepts that must be known to understand the essence of a set 01-concepts that must be known to understand the essence of a set 02-concepts that must be known to understand the essence of a set 03-queue
C stack Concept

1. stack. heap and stack are two concepts.
2. You do not understand this. Local variables are allocated on the stack, with local scopes, automatic program management, and the data on the stack has a global scope, which must be manually recycled.

How can we define the size of a stack segment as needed?

The stack is defined as follows:
Dssg segment stack
Aa dw 512dup (?)
Dssg ends
Generally, you can use the system stack when the PUSH/POP commands are not frequent. However, you must define a stack when you need a stack to store a large amount of data, for example, when passing parameters as subprograms, in addition, the content of a segment cannot exceed 64 K. Because the offset address can only represent 64 K at the maximum, the defined stack cannot be infinitely large. If it exceeds 64 K, let's define two!
The stack is rarely used by beginners in assembly. Generally, it is not required for small programs! It is not difficult to use it, that is, when the return address and register value are used in a subroutine call! In short, it should not be difficult to remember to draw a stack chart when the question is made first!

Related Article

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.