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 3310256
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:44:18+00:00 2026-05-17T21:44:18+00:00

For starters this is apart of my current homework assignment for my Data Structures

  • 0

For starters this is apart of my current homework assignment for my Data Structures class. I am not asking for answers, I am asking for help.

I have a stack class that is implementing a Linked List instead of an array. I am currently trying to write my pop() function. I have a node for my theBack part of the stack.

I am just confused as to getting to the predecesor of my theBack node.

Any help with this would be awesome! Thanks!

  • 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-17T21:44:19+00:00Added an answer on May 17, 2026 at 9:44 pm

    A stack is actually reasonably simple to implement as a singly linked list, due to its restricted push and pop operations. It’s actually a lot easier if you insert pushed elements at the head of the list. Since it’s homework, I’ll provide pseudo-code.

    To initialise a stack, it’s simply creating:

    top -> null
    

    with this code:

    def init (stk):
        stk->top = null                    # just initialise to empty.
    

    Pushing an item is actually inserting it at the start of the list. So, when you push 3, 4 and 5, you get:

           +---+
    top -> | 3 | -> null
           +---+
           +---+    +---+
    top -> | 4 | -> | 3 | -> null
           +---+    +---+
           +---+    +---+    +---+
    top -> | 5 | -> | 4 | -> | 3 | -> null
           +---+    +---+    +---+
    

    with the following code:

    def push (stk, val):
        item = new node                     # Create the node.
        item->value = val                   # Insert value.
        item->next = stk->top               # Point it at current top.
        stk->top = item                     # Change top pointer to point to it.
    

    And popping is then just removing that first node.

    def pop (stk):
        if stk->top == null:                # Catch stack empty error.
            abort with "stack empty"
        first = stk->top                    # Save it for freeing.
        val = first->value                  # Get the value from the top.
        stk->top = first->next              # Set top to the top's next.
        free first                          # Release the memory.
        return val                          # Return the value.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For starters this is a homework question. I have an idea but I am
For starters this is homework, I just really need help with a binary search
For starters, this question is not so much about programming in the NetBeans IDE
How does this syntax look? class Priorities { //Declaring the collective $private family; $private
So for starters lets say that I have a LinkedList<String> , I can easily
For Starters, i would like to note, that this is my first post on
Firstly apologies for the length of this question, and for asking about the Facebook
I'm making an AJAX call which returns XML data, and this is my 'success:'
Goodday, I have a little problem finishing off a project. I am not very
I'm a Facebook programmer newbie. Could anybody recommend good resources for starters? I believe

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.