Stack and its source code analysis in. NET FrameWork

Source: Internet
Author: User

1. The stack operation is a linear table defined at the end of the table. The table end must be inserted or deleted. We call the end of the table the top of the stack, and the other end the bottom of the stack. Stack operations follow the following steps: LIFO: Last
In First Out) or advanced post-output (FILO) principle, so it is also called LIFO table or FILO table.

2. Several common stack operations are represented as follows using interfaces:

Public interface IStack <T> {int GetLength (); bool IsEmpty (); void Clear (); void Push (T item); // T Pop (); // output stack T GetTop ()
} 3. using continuous space to store the elements in the stack is called the sequential stack. we implement a simple ordered stack. The Code is as follows: public class SeqStack <T>: IStack <T> {private int maxsize; private T [] data; private int top; public T this [int index] {get {return data [index];} set {data [index] = value ;}} public int Maxsize {get {return maxsize ;}set {maxsize = value ;}} public int Top {get {return top ;} set {top = value ;}} public SeqStack (int size) {data = new T [size]; maxsize = size; top =-1;} public int GetLength () {return top + 1;} public void Clear () {top =-1;} public bool IsEmpty (){
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.