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

  • SEARCH
  • Home
  • 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 3600190
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:27:50+00:00 2026-05-18T20:27:50+00:00

At run time I want to input two types of datatype, double and string.

  • 0

At run time I want to input two types of datatype, double and string.
One of the condition is that String should pop in the order I input, and double will pop as the usual stack behaviour, LIFO. Another condition is that the stack is limited to max size 10

E.g. one runtime example

Input Hello 1 World 2 blah blah 3 4 5

Output Hello 5 World 4 blah blah 3 2 1

My first question is how many ways is there to solve this problem?
I have solved this problem using 3 stacks, one which stores double, one which store strings, and one which is used to reverse the string order.

I need to save the pattern so the program know which order the doubles comes, thus I save the pattern to the string stack. Since the stack is limited to size 10, I will need to save the pattern in another way.

So this is how my string stack will look like after the push

  1. Hello*
  2. World*
  3. blah
  4. blah***

So when at the first read I need to make specific read in that Stack position and just extract Hello out of it. Asterisk * is left for later use when I tell the program next pop is an double.

My second question is that I wonder if there is some other more elegant solution to this problem. Since my solution will involve some string manipulation to solve this problem. And as for now I’m not actually using the pop function in the string case as it is supposed to be used. I made the solution in C++ btw.

  • 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-18T20:27:50+00:00Added an answer on May 18, 2026 at 8:27 pm

    What you’re doing is fine, except that if you must use a stack, then you aren’t allowed to access random locations in a stack — you can only push/pop — and also it’s not so nice to modify the input strings and store asterisks in them.

    You can solve this using only push/pop operations with 5 stacks (technically, only 4 will be used at any one time, but since they are of different types, you need to declare all 5 in your program):

    stack 1: push doubles in input order

    stack 2: push strings in input order

    stack 3: push data types (double or string) in input order

    stack 4: reverse the order of strings in stack 2

    stack 5: reverse the order of data types in stack 3

    Now pop one data type at a time from stack 5, if it is a double, pop from stack 1, otherwise pop from stack 5, and print the popped value.

    Edit: @jleedev makes a good point that there isn’t a general solution when the stack size is limited. What I’ve described above assumes that you’re allowed to use multiple stacks and each stack can hold as many items as present in the input.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

have a table that dynamically generates text boxes in run time. I want to
At run time I want to dynamically build grid columns (or another display layout)
I want to discover at run-time ONLY the static Methods of a class, how
I want to know, at run time, whether I'm running on 32 bit or
I receive this Run-Time Check Failure upon the return in the following code. I
I need to at run time change the font of a List Control so
It looks like the run-time compiler doesn't support the same language as the command-line
Since I use jQuery 1.3+ all except one timed test is using that. The
I used sprintf method to format data to a string which I want to
I have a form where users input information for a test run on a

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.