C # Data Structure chapter (two stacks) Killertang (original)

Source: Internet
Author: User
C # Data Structure chapter (II) stack



Author: Cold Feather Wolf (Dark_slaer_tang)



Smoke is fast gone, others say smoke is harmful, but to and I is indispensable, hehe. , a smoke program is written out, OK, then add the strength, we finish the stack, in fact, the stack and linear table no big difference, the stack is actually a special linear table, using push pressure input data, pop pop-up data, only use, advanced after the principle, it is so simple. The list class is already written, where we can call it. The code is as follows:



Using System;



Namespace List
{
<summary>
Stack class
</summary>

public class Cstack
{




Call linked List class
Private Clist m_list;




Public Cstack ()
{



Constructors




M_list=new Clist ();



}



<summary>
Push into stack
</summary>

public void Push (int pushvalue)
{
Parameters: int pushvalue data on stack



M_list.append (Pushvalue);

}



<summary>
POPs the stack data and, if it is empty, gets the maximum value of 2147483647 int;
</summary>

public int Pop ()
{
Function: Pop-up stack data



int popvalue;

if (! Isnullstack ())
{



is not an empty stack



Move to the top







Movetop ();



Get the data that pops up
Popvalue=getcurrentvalue ();



Delete



Delete ();
return popvalue;

}



The maximum value of the int type when empty



return 2147483647;
}



<summary>
To determine if the stack is empty
</summary>

public bool Isnullstack ()
{

if (M_list.isnull ())
return true;



return false;
}



<summary>
Number of stacks
</summary>



public int Stacklistcount
{




Get
{
return m_list.listcount;
}

}



<summary>
Move to the bottom of the stack
</summary>



public void Movebottom ()
{



M_list.movefrist ();
}



<summary>
Move to top of stack
</summary>

public void Movetop ()
{
M_list.movelast ();
}



<summary>
Move Up
</summary>

public void MoveUp ()
{
M_list.movenext ();
}



<summary>
Move Up
</summary>

public void MoveDown ()
{
M_list.moveprevious ();
}



<summary>
Get the current value
</summary>

public int GetCurrentValue ()
{
return M_list.getcurrentvalue ();
}



<summary>
Delete to get current node
</summary>

public void Delete ()
{
M_list.delete ();
}



<summary>
Empty stack
</summary>




public void Clear ()



{



M_list.clear ();



}




}
}



Using the previous linked list class, you can easily complete the stack class, in addition to the basic, Pop,push method, but also provide, movebottom,movetop,moveup,movedown, to access the data in the stack, using the GetCurrentValue method, To get the value of the data, you can do more operations, hehe, it's so simple. To be Continue.



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.