Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How do I make this code display the contents of the stack at the top of the text box.?

How do I make this code display the contents of the stack at the top of the text box.?

Scheduled Pinned Locked Moved C#
questiondata-structures
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Angelinna
    wrote on last edited by
    #1

    It is currently displaying the stack upside down, the contents of the top of the stack are displayed as the last line in the text box. I am trying to make this code display the contents of the stack at the top of the text box. :(( private void displayStack() { string nextItem; displayBox.Clear(); for (int i = 0; i <= stackTop; i++) { nextItem = stackArray[i].ToString(); displayBox.AppendText(nextItem); displayBox.AppendText("\n"); } }

    G 1 Reply Last reply
    0
    • A Angelinna

      It is currently displaying the stack upside down, the contents of the top of the stack are displayed as the last line in the text box. I am trying to make this code display the contents of the stack at the top of the text box. :(( private void displayStack() { string nextItem; displayBox.Clear(); for (int i = 0; i <= stackTop; i++) { nextItem = stackArray[i].ToString(); displayBox.AppendText(nextItem); displayBox.AppendText("\n"); } }

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      Just loop the other way.

      Despite everything, the person most likely to be fooling you next is yourself.

      A 1 Reply Last reply
      0
      • G Guffa

        Just loop the other way.

        Despite everything, the person most likely to be fooling you next is yourself.

        A Offline
        A Offline
        Angelinna
        wrote on last edited by
        #3

        How do I do that? :zzz:

        L 1 Reply Last reply
        0
        • A Angelinna

          How do I do that? :zzz:

          L Offline
          L Offline
          Lim Yuxuan
          wrote on last edited by
          #4

          private void displayStack() { string nextItem; displayBox.Clear(); // doing it the other way like guffa said for (int i = stacktop; i >= 0; i--) { nextItem = stackArray[i].ToString(); displayBox.AppendText(nextItem); displayBox.AppendText("\n"); } } instead of starting from bottom value of your stack,(originally your intial conditon is int i = 0) you are now starting at the max value of your stack. Instead of stopping the loop when your variable "i" reaches "stacktop" (top of your stack), the loop stopped at "i = 0"(bottom of your stack). Because of the above 2 statements, i++ have to change to i-- since you are starting from top to bottom now.

          A 1 Reply Last reply
          0
          • L Lim Yuxuan

            private void displayStack() { string nextItem; displayBox.Clear(); // doing it the other way like guffa said for (int i = stacktop; i >= 0; i--) { nextItem = stackArray[i].ToString(); displayBox.AppendText(nextItem); displayBox.AppendText("\n"); } } instead of starting from bottom value of your stack,(originally your intial conditon is int i = 0) you are now starting at the max value of your stack. Instead of stopping the loop when your variable "i" reaches "stacktop" (top of your stack), the loop stopped at "i = 0"(bottom of your stack). Because of the above 2 statements, i++ have to change to i-- since you are starting from top to bottom now.

            A Offline
            A Offline
            Angelinna
            wrote on last edited by
            #5

            Thank you Lim and Guffa.It is now working exactly that way. Thank you so much!!!

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups