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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:01:31+00:00 2026-05-15T14:01:31+00:00

How come void del_begin() crashes when there’s only one node left (I have other

  • 0

How come void del_begin() crashes when there’s only one node left (I have other functions to add nodes)?

 #include <iostream>
 using namesspace std;

 node *start_ptr = NULL;
 node *current;
 int option = 0;
 void del_end()
 {
     node *temp, *temp2;
     temp = start_ptr;
     if (start_ptr == NULL)
         cout << "There are no nodes" << endl;
     else
     {
         while (temp->nxt != NULL)
         {
            temp2 = temp;
            temp = temp->nxt;
         }
         delete temp;
         temp2->nxt = NULL;
     }
 }
 void display()
 {
     node *temp;
     temp = start_ptr;
     cout << endl;
     if (temp == NULL)
         cout << "There are no nodes to display" << endl;
     else
     {
         while(temp != NULL)
         {
        cout << temp->name << ", " << temp->profession << ", " << temp->age;
        if (temp == current)
            cout << "***";
        cout << endl;
        temp = temp->nxt;
        }
        cout << endl;
     }
 }

 int main()
 {
     start_ptr = NULL;
     int option;
      do
     {
         display();
         cout << "0 for EXIT" << endl;
         cout << "1 to ADD TO END" << endl;
         cout << "2 to ADD TO BEGINNING" << endl;
         cout << "3 to DELETE LAST" << endl;
         cout << "4 to DELETE BEGINNING" << endl;
         cout << ">>";
         cin >> option;
         switch (option)
         {
         case 1 : add_end(); break;
         case 2 : add_begin(); break;
         case 3 : del_end(); break;
         case 4 : del_begin(); break;
         }
     }
     while (option != 0);
     return 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-15T14:01:32+00:00Added an answer on May 15, 2026 at 2:01 pm

    You didn’t show us the code for del_begin(), but your del_end() has a bug in the case you’re mentioning (single node list).

    If you have only one node, your while loop will never execute, and temp2 will be uninitialized when you get to the line:

     temp2->nxt = NULL;
    

    Crash!

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

Sidebar

Related Questions

I have come across some c code where the there is an enum type
I have come across a weird problem concerning composite keys and one-to-many relationship. I
I have the following code that I managed to come up with: private void
How come during the linq to xml parse my code is only reading one
How come I can have public void someMethod() { throw new UnsupportedOperationException(); } but
This is what i've come up with so far private void CheckFormatting() { StringReader
How come anonymous functions works as arguments on methods, but not in constructor arguments?
I have come across a class which is non-static, but all the methods and
In following method, public void onPreviewFrame4(byte[] data, Camera camera) data is come in Yuv
How come whenever I have to use awakeFromNib protocol I have to put it

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.