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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:38:30+00:00 2026-06-15T04:38:30+00:00

My instructor defined the function remove() as: struct node { node *next; int value;

  • 0

My instructor defined the function remove() as:

struct node
{
  node *next;
  int value;
}

int IntList::remove()
{
  node *victim = first;
  int result;

  if(isEmpty()) throw listIsEmpty();

  first = victim->next;
  result = victim->value;
  delete victim;
  return result;
}

Where first “points to the sequence of nodes representing this IntList.”

If victim and first both point to the same thing, and we delete victim, doesn’t this delete first as well?

  • 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-15T04:38:32+00:00Added an answer on June 15, 2026 at 4:38 am

    If victim and first both point to the same thing, and we delete victim, doesn’t this delete first as well?

    At the time of deletion, they do not point to the same thing.

    Basically what’s happening here is that the the second node is becoming the first node, and then the old first node is being deleted.

    Since first = victim->next before the delete, first == victim will never be the same unless victim->next == victim which should never happen in a linked list.


    For a way simplified example, assume:

    first is at address 0xDEAD (crazy address, but go with it)
    first->next is at address 0xF00D
    

    Then it goes down like this:

    node *victim = first; //victim = 0xDEAD
    first = victim->next; //first = 0xF00D, so first now = first->next
    delete victim; //victim = 0xDEAD, so you deleted the original first
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using libssh2 and have a callback function defined outside my SSHWrapper object: static
My instructor said the way to start this is to use the getline() function
I am the lead instructor of web & internet related courses on a private
I'm a teacher(instructor) of CS in the university. The course is based on Cormen
I'm working through SICP on my own, so I don't have an instructor to
I have such tables in my database like Customer , Member , Instructor ,
I'm a newbie using OpenMP with C++. I was doing a simple function, loading
I have defined and enum in cython header file api.pxd : ctypedef enum InstructionType:
I have the Client class defined. I also have Mapping\ClientMap.cs file that defines column
I'm working on a project for school and the instructor insists that all code

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.