usingSystem;usingSystem.Collections.Generic;classGFG{// Pushing element on the top of the stackstaticvoidstack_push(Stack<int> stack){for(int i =0; i <5; i++){
stack.Push(i);}}// Popping element from the top of the stackstaticvoidstack_pop(Stack<int> stack){
Console.WriteLine("Pop :");for(int i =0; i <5; i++){int y =(int)stack.Pop();
Console.WriteLine(y);}}// Displaying element on the top of the stackstaticvoidstack_peek(Stack<int> stack){int element =(int)stack.Peek();
Console.WriteLine("Element on stack top : "+ element);}// Searching element in the stackstaticvoidstack_search(Stack<int> stack,int element){bool pos = stack.Contains(element);if(pos ==false)
Console.WriteLine("Element not found");else
Console.WriteLine("Element is found at position "+ pos);}// Driver codepublicstaticvoidMain(String[] args){Stack<int> stack =newStack<int>();stack_push(stack);stack_pop(stack);stack_push(stack);stack_peek(stack);stack_search(stack,2);stack_search(stack,6);}}// This code contributed by Rajput-Ji
C#
success
تم تقديم إجابتك بنجاح
success
تم تعديل الإجابة، سيتم نشرها بعد مراجعة الإدارة