Question

In: Computer Science

Create a program in C++ implementing the LinkedStack 7. Write a client that removes all negative...

Create a program in C++ implementing the LinkedStack

7. Write a client that removes all negative numbers from a stack of int objects. If the original stack contained the integers 30, –15, 20, –25 (top of stack), the new stack should contain the integers 30, 20.

Solutions

Expert Solution

#include <iostream>

utilizing namespace sexually transmitted disease;

/struct hub for connect

struct Node

{

int information;

Hub *next;

};

/single myStack

class LinkedStack

{

private:

Hub *head;

public:

LinkedStack()

{

head=NULL;

}

/adding hub to interface

void push(int esteem)

{

Hub *temp=new Node;

temp->data=value;

temp->next=NULL;

if(head==NULL)

{

head=temp;

temp=NULL;

}else{

temp->next = head;

head = temp;

}

}

/show interface

void print()

{

Hub *temp=new Node;

temp=head;

while(temp!=NULL)

{

cout<<temp->data<<" ";

temp=temp->next;

}

cout<<endl;

}

/show interface

void removeAllNegative()

{

Hub *temp=new Node;

temp=head;

/eliminate from first

while(temp->data<0){

head = temp->next;

temp = temp->next;

}

Hub *prev=temp;

while(temp!=NULL)

{

if(temp->data<0){

prev->next = temp->next;

}

prev = temp;

temp = temp->next;

}

cout<<endl;

}

};

int main(){

LinkedStack myStack;

myStack.push(- 25);

myStack.push(20);

myStack.push(- 15);

myStack.push(30);

cout<<"Original myStack"<<endl;

myStack.print();

myStack.removeAllNegative();

cout<<"After eliminating negative myStack"<<endl;

myStack.print();

bring 0 back;

}

/*If this helps you, please let me know by giving a positive thumbs up. In case you have any queries, do let me know. I will revert back to you. Thank you!!*/


Related Solutions

1) a. Write a C++ program for the recursive algorithm that removes all occurrences of a...
1) a. Write a C++ program for the recursive algorithm that removes all occurrences of a specific character from a string b. Write the pseudocode for the program.
Write a C program for the recursive algorithm that removes all occurrences of a specific character...
Write a C program for the recursive algorithm that removes all occurrences of a specific character from a string. (please comment the code)
Program in C Write a function that takes a string as an argument and removes the...
Program in C Write a function that takes a string as an argument and removes the spaces from the string.
Write a C++ program that uses a de-duplication function that iteratively sanitizes (removes) all consecutive duplicates...
Write a C++ program that uses a de-duplication function that iteratively sanitizes (removes) all consecutive duplicates in a C++ string. Consecutive duplicates are a pair of duplicate English alphabets sitting next to each other in the input string. Example: "AA", "KK", etc., are all consecutive duplicates. This function will internally run as many iterations as needed to remove all consecutive duplicates until there is either no consecutive duplicates left, or the string becomes empty (in which the function returns "Empty"...
Client AND server using names pipes (mkfifo) in C/C++ Write and client program that will talk...
Client AND server using names pipes (mkfifo) in C/C++ Write and client program that will talk to a server program in two separate terminals. Write the server program that can handle multiple clients (so threads will be needed) and with fork() and exec()
Please write program in C++ format: Write a program to accept five negative numbers from the...
Please write program in C++ format: Write a program to accept five negative numbers from the user. (1) Find the average of the five numbers and display the answer to the standard output. Keep the answer two decimal points - 5 points (2) Output the numbers in ascending order and display the answer to the standard output. - 5 points
in C programming language Write a function removeDups that removes all duplicates in a given array...
in C programming language Write a function removeDups that removes all duplicates in a given array of type int. Sample Test Case: input -> {1,2,2,2,3,3,4,2,4,5,6,6} output -> {1,2,3,4,5,6,0,0,0,0,0,0} More specifically, the algorithm should only keep the first occurance of each element in the array, in the order they appear. In order to keep the array at the same length, we will replace the removed elements with zeros, and move them to the end of the array.
write a Program in C++ Using a structure (struct) for a timeType, create a program to...
write a Program in C++ Using a structure (struct) for a timeType, create a program to read in 2 times into structures, and call the method addTime, in the format: t3 = addTime(t1, t2); Make sure to use add the code to reset and carry, when adding 2 times. Also, display the resultant time using a function: display(t3);
********************C# C# C#******************** Part A: Create a project with a Program class and write the following...
********************C# C# C#******************** Part A: Create a project with a Program class and write the following two methods(headers provided) as described below: 1. A Method, public static int InputValue(int min, int max), to input an integer number that is between (inclusive) the range of a lower bound and an upper bound. The method should accept the lower bound and the upper bound as two parameters and allow users to re-enter the number if the number is not in the range...
write a c++ program an expression that determines if an integer, n is a negative four...
write a c++ program an expression that determines if an integer, n is a negative four digit number. write a c++ program an expression that determines if a string, wd, equals "so" ignoring case.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT