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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:21:36+00:00 2026-06-07T03:21:36+00:00

Here is a part of code for deleting an element from the tail a

  • 0

Here is a part of code for deleting an element from the tail a singly Linked List:

int SLList::deleteFromTail()
{
    int el = tail->info;

    //if the list has only one element
    if(head == tail) {
        delete head;
        head = tail = 0;
    }
    else {
        //some code here...
    }

    return el
}

Here head and tail are pointers to first and last element of LL, respectively.

In the if block above after delete head we are setting head = tail = 0.

But after we have deleted head, how can we set it’s value to something? (NULL in this case)

  • 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-06-07T03:21:38+00:00Added an answer on June 7, 2026 at 3:21 am

    Head is a pointer. You are deleting an object pointed by the pointer, not the pointer itself

    Consider this example:

    Foo *foo = new Foo(); //foo does not store Foo object. Just an adress of created object.
    //do some stuff
    delete foo; //object is deleted
    foo = new Foo(); //create another Foo and make foo point to it
    

    EDIT
    A pointer is just an adress ob an object. When you write delete head you delete the object pointed by head, but even after deletion head pointer will point to the same place as before. But dereferencing it (e.g. *head) will cause problems.

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

Sidebar

Related Questions

The following code is taken from here . I removed all Windows NT part
My problem is deleting a node from linked list. I have two structs :
Here is part of my code: extern C REGISTRATION_API int extreme(char* lKey) { string
Here's part of my code for a jQuery word counter. My question is: how
I need a fix for this. here is just part of my code <?php
Here is a part of my html code (video urls marked with a django-template
Just putting part of some code here where I am writing two values to
Here is the first part of my controller code: public class ControlMController : Controller
Ok here is part of the code that is causing the error: char charlieReturn[10000];
i want to get the value from the cursor without the SimpleCursorAdapter part.here is

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.