Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 731573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:02:32+00:00 2026-05-14T07:02:32+00:00

I’ve been thinking about a program logic, but I cannot draw a conclusion to

  • 0

I’ve been thinking about a program logic, but I cannot draw a conclusion to my problem.

Here, I’ve implemented stack and queue operations to a fixed array.

int A[1000];
int size=1000;

int top;

int front;
int rear;

bool StackIsEmpty()
{
    return (top==0);
}

bool StackPush( int x )
{
    if ( top >= size ) return false;
    A[top++] = x;
    return true;
}

int StackTop( )
{
    return A[top-1];
}

bool StackPop()
{
    if ( top <= 0 ) return false;
    A[--top] = 0;
    return true;
}

bool QueueIsEmpty()
{
    return (front==rear);
}

bool QueuePush( int x )
{
    if ( rear >= size ) return false;
    A[rear++] = x;
    return true;
}

int QueueFront( )
{
    return A[front];
}

bool QueuePop()
{
    if ( front >= rear ) return false;
    A[front++] = 0;
    return true;
}

It is presumed(or obvious) that the bottom of the stack and the front of the queue is pointing at the same location, and vice versa(top of the stack points the same location as rear of the queue).

For example, integer 1 and 2 is inside an array in order of writing. And if I call StackPop(), the integer 2 will be popped out, and if I call QueuePop(), the integer 1 will be popped out.

My problem is that I don’t know what happens if I do both stack and queue operations on the same array. The example above is easy to work out, because there are only two values involved. But what if there are more than 2 values involved?

For example, if I call

StackPush(1);
QueuePush(2);
QueuePush(4);
StackPop();
StackPush(5);
QueuePop();

what values will be returned in the order of bottom(front) from the final array?

I know that if I code a program, I would receive a quick answer. But the reason I’m asking this is because I want to hear a logical explanations from a human being, not a computer.

ADDED:
For the second example, I have 4 candidates.
25
12
24
45
or no answer from here at all.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T07:02:33+00:00Added an answer on May 14, 2026 at 7:02 am

    In the case of your code, it will probably not do what you expect since the stack routines and the queue routines maintain different variables for where to push to.

    StackPush(1);   // place 1 at position 0; increase top of stack to 1
    QueuePush(2);   // place 2 at position 0; increase rear of queue to 1
    QueuePush(4);   // place 4 at position 1; increase rear of queue to 2
    StackPop();     // get value(2) from position 0; decrease top of stack to 0
    StackPush(5);   // place 5 at position 0; increase top of stack to 1
    QueuePop();     // get value(5) from position 0; increase front of queue to 1
    

    If you instead wrote the code so that the stack use rear instead of top, then you would see these results.

    StackPush(1);   // place 1 at position 0; increase rear to 1
    QueuePush(2);   // place 2 at position 1; increase rear to 2
    QueuePush(4);   // place 4 at position 2; increase rear to 3
    StackPop();     // get value(4) from position 2; decrease rear to 2
    StackPush(5);   // place 5 at position 2; increase rear to 3
    QueuePop();     // get value(1) from position 0; increase front to 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 446k
  • Answers 446k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Since a SortOrder enumeration can technically take on more than… May 15, 2026 at 7:23 pm
  • Editorial Team
    Editorial Team added an answer I couldn't solve it using blocking sockets. I had to… May 15, 2026 at 7:23 pm
  • Editorial Team
    Editorial Team added an answer If I understand your question, you just want to get… May 15, 2026 at 7:23 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.