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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:59:17+00:00 2026-05-30T08:59:17+00:00

there’s something I can’t get my head round… Basically I’m given the following data

  • 0

there’s something I can’t get my head round…
Basically I’m given the following data structure:

struct node_ll {
    int payload;
    node_ll *next;  //pointer to next node
};

Which is essentially a stack of numbers.
I need to create a method with the following prototype:

int tail_return(node_ll **list)

where **list is the memory address of the above data structure. My implementation is as follows:

int tail_return(node_ll **list) {

    node_ll *temp;
    temp = *list;

    node_ll *prev_temp;
    prev_temp = *list;

    bool firstPass = true;

    while(temp){

        if(firstPass == true){
        temp = temp->next;
        firstPass = false;

        } else {
            temp = temp->next;
            prev_temp = prev_temp->next;

        }
    }

    int toReturn = prev_temp->payload;

    prev_temp->payload = 0;
    (**list).next = prev_temp;

    delete temp;
    delete prev_temp;
    return toReturn;
}

However I get the following output from test runs:

List a after head insertion of 2,4,6,8,10 elements:

{10,8,6,4,2}

now removing the last element

DELETED: 2

{10,0} where it's supposed to be: {10,8,6,4}

What am I doing wrong? Apparently the method finds the right value to delete – 2. But why when I try to print it after deletion I end up with 10 and 0?

  • 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-30T08:59:19+00:00Added an answer on May 30, 2026 at 8:59 am
     (**list).next = prev_temp;
    

    should be

    prev_temp->next = 0 ; 
    

    when you do (**list).next = prev_temp; you are manipulating the parameter which was passed to your method and not the last node in the linked list.

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

Sidebar

Related Questions

There are a few ways to get class-like behavior in javascript, the most common
There are many string matching algorithms can be used to find a pattern (string)
There's a thrird party app that needs to get information via custom http headers,
There can only be one IDENTITY column per table Why is it so? Take
There's no Sort() function for IList . Can someoene help me with this? I
There is something I miss with the notion of Synchronizing code in Android. Scenario
There's a lot of reading on self referencing problems, but I can't seem to
There are many algorithms for finding optimal binary search trees given a set of
There is a conversion process that is needed when migrating Visual Studio 2005 web
There are two weird operators in C#: the true operator the false operator If

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.