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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T13:13:10+00:00 2026-05-20T13:13:10+00:00

The following routine is expected to remove the node at the start of a

  • 0

The following routine is expected to remove the node at the start of a single linked list but it fails sometimes.

void remove_from_front(node *start)
{
    delete start;
    start = start->link;
    print_list(start);
}
  • 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-20T13:13:10+00:00Added an answer on May 20, 2026 at 1:13 pm

    There are few problems I can see:

    1. You are freeing the start node and then accessing the freed memory. This is incorrect, it leads to undefined behavior which means anything can happen. In one run it might work and in the next run it might crash.

    2. Your function needs to make changes to the head of the list but it is not making the changes visible to the called function as it is not returning anything and the argument start is passed by value. To fix this either pass the address or reference of the start pointer.

    3. Your function might be called on an empty list, start = NULL. You need to handle that case.

    Correct implementation:

    void remove_from_front(node **start) {
    
      // if list is empty..nothing to remove..return.
      if(*start == NULL) {
         return;
      }
    
      // save the address of the node following the start in new_start 
      node *new_start = (*start)->link;
    
      // now delete the start node.
      delete *start;
    
     // new_start is now the new start of the list.
     // And since start was passed by address, the change is reflected in the
     // calling function.
      *start = new_start;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following native routine: void sendMessage(const char* text) { JNIEnv* env; if(!_jvm)
Searching online, I have found the following routine for calculating the sign of a
In my Fortran code I made the following call to the dnrm2 routine: d
When I try to run a routine I get the following error: Error Code:
I have the following routine that dumps a DataTable into an Excel worksheet. private
We are using the following routine (on Linux, with libudev) to read data from
for a day now I stare at the following routine and can't get my
The following code was a proof of concept for a message batching routine. Do
Trying to create the following routine in MySQL Workbench yields a This object's DDL
I've written the following routine to manually traverse through a directory and calculate its

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.