A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /home/premierconsult/public_html/index.php:65)

Filename: core/Input.php

Line Number: 408

A PHP Error was encountered

Severity: Warning

Message: session_start(): Cannot send session cookie - headers already sent by (output started at /home/premierconsult/public_html/index.php:65)

Filename: Session/Session.php

Line Number: 143

A PHP Error was encountered

Severity: Warning

Message: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/premierconsult/public_html/index.php:65)

Filename: Session/Session.php

Line Number: 143

A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /home/premierconsult/public_html/index.php:65)

Filename: controllers/Questions.php

Line Number: 330

example of LIFO approach using c# Programming

example of LIFO approach using c# Programming


Write code that implements LIFO approach using c# programming

الأجوبة


using System;
using System.Collections.Generic;

class GFG
{
	// Pushing element on the top of the stack
	static void stack_push(Stack<int> stack)
	{
		for (int i = 0; i < 5; i++)
		{
			stack.Push(i);
		}
	}

	// Popping element from the top of the stack
	static void stack_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 stack
	static void stack_peek(Stack<int> stack)
	{
		int element = (int)stack.Peek();
		Console.WriteLine("Element on stack top : " + element);
	}

	// Searching element in the stack
	static void stack_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 code
	public static void Main(String[] args)
	{
		Stack<int> stack = new Stack<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
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...