Hello everyone! Just made the account today, so please be gentle. I am looking for help with a series of eight questions that I have been having trouble with, if you guys or anyone can help me out with them I'll greatly appreciate it! If you guys/gals can help with also giving a lot of input on the answers and why that answer is the answer, if it isn't much trouble for you guys. The following questions that I have been having trouble with are:
1) Remember: A stack is a Last in First Out data structure. Write a function called FIFOPrinto that prints the item in a stack S in First In First Out order. That is, you should print items in S in the order in which they were pushed. At the end of your function, the elements in S should be exactly in the same order they were when the function began execution. Your function may use one additional stack T to help get the job done. No other data structures are permitted. Declare other variables as you see fit. You are only allowed to use the functions in the Stack ADT. Your function should fit the outline shown below.
void FIFOPrint (Stack& S){
Stack T; //initially empty stack T
//Complete this function
}
2) Given the following outputs from the inorder and preorder traversals of a binary search tree:
INORDER: 1,6,9,19,31,54,87,96
PREORDER: 19,6,1,9,87,54,31,96
a. Which value is at the root of tree?
b. How many values are in the left subtree of the root?
c. What is the root of the right subtree?
3) Write a code fragment to exchange two adjacent nodes of a doubly linked list. Assume that the pointer variable cursor points to the first of the two nodes. NOTE!!! I want to exchange the two NOdes, not just their values in the two nodes. ASSUME:
-The variable head points to the first Node of the linked list
-The variable cursor does not point to the first node of the linked list.
4) Binary search tree:
a. insert the following values into an initially empty binary search tree: 35,25,15,5,3,28,18,8,20,40. Show the resultant binary search tree.
b. what are the values encountered in the search for the (non-existent) value 23 in this tree?
5) Has a binary search tree, with the values: 15,10,4,2,0,35,18,1,23,16,9,3. What order are they placed in.
6) A DEQueue is a queue-like data structure that allows you to add items to either end of the queue, and remove items from either end of the queue. The class declaration is shown below (for a dequeue based on linked lists). COmplete the four incomplete functions (listed after the class declaration).
class DEQUeue{
public:
DEQueue(); //constructor
void enqueue_front (int item);
void enqueue_back (int item);
int dequeue_front ();
int dequeue_back ();
bool isEmpty ();
private:
Node * front;
Node * last;
};
DEQueue::DEQueue(){
front = last = 0;
}
bool DEQueue::isEmpty(){
return front == 0 ;
}
void DEQueue::add_front(int item){
// Complete this function
}
void DEQueue::add_back(int item){
// Complete this function
}
int DEQueue::remove_front(){
// Complete this function
}
int DEQueue::remove_back(){
// Complete this function
}
7) What is the output for the following program?
#include <iostream>
#include <string>
using namespace std;
void threePar(int r, int *s, int & t){
int temp = 20;
*s = r;
t = *s;
r = temp;
}
int main (){
int x, y , z;
int *ptr;
x = 5;
y = 10;
z = 15;
ptr = & y;
cout << "Before: " << x << " " << y << " " << z << endl;
threePar (x, ptr, z); // call
cout << "After : " << x << " " << y << " " << z << endl;
return 0;
}
8) Here is the recursive logic for finding the smallest value in a binary tree of positive numbers, given a pointer to the root node of the binary tree:
a. if the tree is empty, return -1
b. recursively find the smallest value in the left-subtree, and call it minL
c. recursively find the smallest value in the right-subtree, and call it minR
d. compare the value at the root with minL and minR, and return the smallest value
now complete the recursive function below to implement the logic described above(or write your own recursive function to do the task).
CODE!:
int BinaryTree::minTree(BinaryTreeNode *root){
if (root == 0){ //tree is empty?
return -1;
}
else{
int minL, minR, min;
minL = /* Fill in the code here */;
minR = /* Fill in the code here */
min = root->data;
if ( /* fill code here * /)
{
/* Fill code here */
}
if ( /* fill code here */)
}
/* Fill code here */
}
return min;
}
}
Thanks in advance for all the help you guys can give me, these questions have been giving me a hard time for the past few days now and I'm hoping you guys/gals can help me out with helping me with these questions. Appreciate all the help and advice!