NinjaLink -2 Posting Pro in Training

I am writing program segments (not real programs or functions) to make sure if I understand how to do each one by using "push/pops for stacks" and "addQueue and DeleteQueue for Queues". Can someone please help me with these questions. I don't know if I am correct or not!


1. Using a stack operation, write a programming segment that will copy every other item in Stack1 to Stack2 leaving Stack1 unchanged.

int val;

while (!s.isEmpty())
{
s.pop();
c.push(val);
}

while (!c.isEmpty())
{
c.pop();
s.push(val);
copy.push(val);
}
}

2. Using queue operations, write a programming segment that will square all of the numbers in a Queue1 unchanged. Copy all the numbers in which the square is divisible by 2 into Queue2. Leaving Queue1 unchanged.

int val;

if (!s.isEmptyQueue())
{
for (int i = queueFront; i < queueRear; i--)
{
Queue1.deleteQueue();
Queue2.addQueue(val);

product = val * val;
}

for ( i = queueFront; i < queueRear; i++)
{

val = val/2;

Queue2.deleteQueue();
Queue1.addQueue(val);
}

else
{
cout<<"It is empty";
}

3. Use Queue and Stack Operations assume that the Queue and the Stack have the same number of items and all items are the same data type. Write a programming segment that determines sequentially if the numbers in a Stack are the square of the numbers in a Queue.

bool item = false;

while (!Queue.deleteQueue())
{
Queue.deleteQueue();
Queue2.addQueue(val);
Stack.push(val);
}

while (!Stack.isEmpty())
{

Stack.pop();
Stack2.push(val);
}

for (int i = queueFront; i < queueRear; i--)
{
for (int i = top; i < top; i -- )
{ 
if (queueFront == (top*2) )
{
item = true;
break;
}
else
item = false;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.