Set> stack Stack

Source: Internet
Author: User

Stack: first warehouse, first warehouse, then warehouse, and then warehouse.

Set> stack> Create Stack

Code Using system;
Using system. Collections. Generic;
Using system. text;
Using system. collections;

Namespace consoleapplication1
{
Class Program
{
Static void main (string [] ARGs)
{
// Use the default capacity
Stack sack = new stack ();
// Use the collection element in the string array to initialize the stack object
Stack sack1 = new stack (New String [5] {"Stack element 1", "Stack element 2", "Stack element 3", "Stack element 4 ", "Stack element 5 "});
// Create a stack object and specify 20 Elements
Stack sack2 = new stack (20 );
}
}
}

Set> stack> the inbound and outbound stacks of Elements

Code Using system;
Using system. Collections. Generic;
Using system. text;
Using system. collections;

Namespace consoleapplication1
{
Class Program
{
Static void main (string [] ARGs)
{
Stack Sk = new stack ();
SK. Push ("Stack element 1"); // push method to implement element inbound Stack
SK. Push ("Stack element 2 ");
SK. Push ("Stack element 3 ");
SK. Push ("Stack element 4 ");
Displayresult (SK );
Console. writeline ("the element at the top of the stack is :");
Console. writeline (SK. Peek (); // The peek method is used to obtain the top Element Object. This method does not remove the top element.
Console. writeline ("Remove the top element: {0}", SK. Pop (); // The pop method implements the element exit stack.
Console. writeline ("the elements in the current stack are :");
Displayresult (SK );
Console. Readline ();
}
Static void displayresult (stack SK)
{
Foreach (Object s in SK)
{
Console. writeline (s );
}
}
}
}

 

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.