Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Here is LStack using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Statck_LinkedList { public class Node { public int item; public Node link; public

image text in transcribed

Here is LStack

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace Statck_LinkedList

{

public class Node

{

public int item;

public Node link;

public Node(int theItem)

{

item = theItem;

link = null;

}

}

public class LinkedList

{

public Node header;

public LinkedList()

{

header = null;

}

public void Append(int newItem)

{

Node newNode = new Node(newItem);

newNode.link = header;

header = newNode;

}

public int Remove()

{

if (header != null)

{

int x = header.item;

header = header.link;

return x;

}

else

{

Console.WriteLine("\aThe list is empty!");

return -1;

}

}

public void PrintList()

{

Node current = header;

if (current == null) Console.WriteLine("The list is empty!");

else

{

Console.WriteLine(current.item);

while (!(current.link == null))

{

current = current.link;

Console.WriteLine(current.item);

}

}

}

}

public class LStack

{

LinkedList ll;

public LStack()

{

ll = new LinkedList();

}

public void Push(int x)

{

ll.Append(x);

}

public int Pop()

{

return ll.Remove();

}

public void Print()

{

ll.PrintList();

}

}

class Program

{

static void Main(string[] args)

{

int num, flag, p;

LStack listStack = new LStack();

Random rnd = new Random(100);

for (int i = 0; i

{

num = rnd.Next(1, 100);

listStack.Push(num);

}

listStack.Print();

Console.WriteLine(" Enter 1 to pop , 2 to phsh an interger, 3 to exit.");

flag = int.Parse(Console.ReadLine());

while (flag != 3)

{

if (flag == 1)

{

p = listStack.Pop();

Console.WriteLine(" The item poped out is: {0}", p);

Console.WriteLine(" The items in the Stack after pop are:");

listStack.Print();

}

else

if (flag == 2)

{

Console.WriteLine(" Enter an integer to push it into the Stack:");

p = int.Parse(Console.ReadLine());

listStack.Push(p);

Console.WriteLine(" The items in the Stack after pushing are:");

listStack.Print();

}

Console.WriteLine(" Enter 1 to pop , 2 to phsh an interger, 3 to exit.");

flag = int.Parse(Console.ReadLine());

}

}

}

}

Include LStack class in your program. 1. Write a program that uses a stack of characters to check if a string of user input is a Palindrome or not. A palindrome is a word, phrase, or sequence that reads the same backward as forward e.g., madam. nter a string: abcde is is Not a palindrom! Enter a string: radar This is a palindrom

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

=+and non-compete agreements in three to five different countries.

Answered: 1 week ago