Write 2 classes that implement a stack with push, pop and peek operations. One s
ID: 3682705 • Letter: W
Question
Write 2 classes that implement a stack with push, pop and peek operations. One should be called StackL and internally should store the data in a series of Nodes as a singly linked list. The other, StackO, can use a different data structure of your choice.
Write a console application to determine the time required to perform the push/pop or queue/dequeue operations on your stacks and queues. Make an instance of a C# stack and a C# queue. Get the time required to push 10,000,000 values onto each stack and then get the time required to pop 10,000,000 values from each stack.
Explanation / Answer
/*HEADERS*/
using System;
using System.Collections;
namespace stackApplication
/*MAIN METHOD*/
{
/*Class intilization*/
class stackData
{
/*MAIN STRUCTURE*/
static void Main(string[] args)
{
/*Assigning the values*/
Stack st = new Stack();
st.Push('RANDOM');
st.Push('PLANTS');
st.Push('WOOD');
st.Push('CARAM');
/*STACK VARAIATION*/
Console.WriteLine("Current stack: ");
/*LOOP*/
foreach (char c in st)
{
Console.Write(c + " ");
}
Console.WriteLine();
st.Push('V');
st.Push('H');
Console.WriteLine("The next poppable value in stack: {0}", st.Peek());
Console.WriteLine("Current stack: ");
foreach (char c in st)
{
Console.Write(c + " ");
}
Console.WriteLine();
Console.WriteLine("Removing values ");
st.Pop();
st.Pop();
st.Pop();
Console.WriteLine("Current stack: ");
foreach (char c in st)
{
Console.Write(c + " ");
}
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.