Stack definition and concept Stack is a linear table that only inserts and deletes operations at one end of the table.
( 1 ) Usually referred to as the end of the insert or delete stack is the top, and the other end is called the bottom of the stack ).
( 2 When there are no elements in the table, it is called an empty stack.
( 3 Stack is a linear table of last in first out (LIFO.
Stack modification is based on the principle of "back-to-first-out. Each deletion (rollback) is always in the current stack " Latest " The last element to be inserted into the stack. The first element to be inserted is placed at the bottom of the stack. Stack in C #CodeImplementation
Using System;
Namespace Everydaystudy. Data Structure
{
Public Class Dapstack
{
Private Object [] _ Array;
Private Const Int _ Defacapcapacity = 10 ;
Private Int _ Size;
PublicDapstack ()
{
_ Array= New Object[_ Defacapcapacity];
_ Size= 0;
}
Public Dapstack ( Int Initialcapacity)
{
If (Initialcapacity < 0 )
{
Throw New Argumentoutofrangeexception ( " Stack space cannot be less than zero " );
}
If (Initialcapacity < _ Defacapcapacity)
{
Initialcapacity = _ Defacapcapacity;
}
_ Array= New Object[Initialcapacity];
_ Size= 0;
}
Public Virtual Object Pop ()
{
If (_ Size = 0 )
{
Throw New Invalidoperationexception ( " There is no data in the stack. " );
}
Object Obj2 = _ Array [ -- This . _ SIZE];
_ Array [_ SIZE] = Null ;
Return Obj2;
}
Public Virtual Void Push ( Object OBJ)
{
If (_ Size = _ Array. length)
{
Object [] Destinationarray = New Object [ 2 * _ Array. Length];
_ Array = Destinationarray;
}
_ Array [_ size ++ ] = OBJ;
}
PublicVirtual IntCount
{
Get
{
Return_ Size;
}
}
}
}
Others
There seems to be nothing to pay attention to, probably because the stack structure is exposed too much when we go to school, so we can understand this stack.
I will not talk about other things. I will use this book to write about the wireless applications of other people's families so late. Well, if you have any questions, try again. Wait until you get to bed and tomorrow will go to work.