C++
Using the Stack operations, write a pseudocode routine, dupA, that
takes aStack for string, checks to see if the top starts with ‘A’
or ‘a’. If so, duplicate the top of the stack (i.e. push a copy of
that value onto the stack) else if length > 10, pop it off the
stack
C++ implentation of above problem is in following screenshot:
Here the output:
if TOS(top of stack) = a
if TOS= A
if stack length > 10
if no condition is matched
Here is the code:
#include <iostream>
#include <stack>
using namespace std;
stack<char> st; // Global stack variable
void display() // Stack display function
{ while (!st.empty()) {
cout<< st.top()<<"\n";
st.pop();
}
}
int main() {
string name; // user input
string
cout<<"Enter any String: ";
cin>>name;
for(int i=0;i<name.size();i++) // pushing the
elements into stack
st.push(name[i]);
if(st.top()=='A' || st.top()=='a') // condition
checking for A or a
{
cout<<"TOP of
Stack: "<<st.top()<<"\n";
st.push(st.top());
cout<<"Duplicating
the TOP of Stack....\n";
cout<<"Stack
elements are: \n";
display();
}
else if (st.size()>10) // condition checking
for stack length
{
cout<<"Stack
length is: "<<st.size()<<"\n";
cout<<"Stack
elements are: \n";
display();
}
else {cout<<"Stack elements are:
\n";
display();}
}
C++ Using the Stack operations, write a pseudocode routine, dupA, that takes aStack for string, checks...
Need help. write a C program stack-ptr.c that implements a stack using a link list. Below is a skeleton code to start with.Jjust edit to make thread friendly. examplpe: push(5, &top); push(10, &top); push(15, &top); int value = pop(&top); value = pop(&top); value = pop(&top); this program currently has a race condition. use Pthread mutex locks to fix the race conditions. test you now thread safe stack by creating 200 concurrent threads in main() that push and pop values. -use...
Suppose we execute the following stack operations on a stack of ints. push(1); pop(); // #1 push(10); pop(); // #2 push(7); push(4); push(3); pop(); // #3 push(5); pop(); //#4 Write the final state of the stack, and for each pop() operation, write the value that will be popped off the stack (pops are numbered so you can refer to them).
Java Write a pseudocode and Java program to implement the Stack using arrays. Write Push(), Pop(),and Display() methods to demonstrate that it works.
Stacks There are two main operations associated with stacks; 1) putting things on the stack which is referred to as push, 2) taking things from the stack which is referred to as pop. We can create a stack using linked lists if we force ourselves to insert and remove nodes only at the top of the list. One use of a stack is when you want to write a word backward. In that case, you will read the letters of...
Create a C++ program. Include comment, input and output file. STACK IMPLEMENTATION USING AN link list IMPLEMENT THE FOLLOWING STACK OPERATIONS using a TEMPLATED CLASS. WRITE ALL THE FULL-FUNCTION DEFINITIONS NEEDED for the OPERATIONS. OUTPUT: PRINT ALL THE ELEMENTS ON THE STACK. Stack Operations initializestack: Initializes the stack to an empty state. isEmptyStack: Determines whether the stack is empty. If the stack is empty, it returns the value true; otherwise, it returns the value false. isFul1stack: Determines whether the stack...
Dynamic Implementation of Stack - The purpose is to use our dynamic implementation of stack. The application will be to add large numbers. Review adding large numbers Remember that we can use stacks to safely add integer values that overflow the int data type g. in Java, the maximum possible int value Integer.MAX_VALUE is: 2147483647 so any int addition larger than this will overflow and fail Using stacks to add large numbers safely Will actually represent the large integers to...
Python: using a stack, implement a function that takes in an arithmetic expression, and evaluates it, supported operations are + and -, which have same precedence. Note: one way to do it is to scan the entire expr pushing numbers onto val-stack and operations on op-stack until tokens in expr are done. Then, use a loop to pop two numbers from val-stack and one operation from op-stack, evaluate, and push results back to val-stack, until op-stack is empty.
Write a program that uses a stack to reverse its inputs. Your stack must be generic and you must demonstrate that it accepts both String and Integer types. Your stack must implement the following methods: push, pop, isEmpty (returns true if the stack is empty and false otherwise), and size (returns an integer value for the number of items in the stack). You may use either an ArrayList or a LinkedList to implement your stack. Also, your pop method must...
a)Complete the following LC-3 PUSH routine. Assume R6 is the stack pointer, st grows towards 0 and each element of the stack takes four memory locations PUSH ADD R6, R6, STR RO, R6, lowing operations, what are the contents of the stack? Show what the ck contains after each operation and the final stack contents. Multiply routine takes two operands off the stack, multiplies and pushes the result back on the stack push 2 push 2 multiply If the stack...
11.2 Problem Set 2: PostScript Stack Commands (in python please) For this assignment you are to implement a PostScript command interpreter using a Stack. You must implement the stack using a singly-linked list. Solutions that use a data structure other than a singly-linked list will received no credit. The interpreter must read and execute a string of PostScript commands based on the following definitions: 1. = objn objn-1 … obj1 = : objn-1 … obj1 This command removes the topmost...