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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:25:13+00:00 2026-06-03T17:25:13+00:00

class List { ListNode *head; ListNode *prev; }; class ListNode { int data; ListNode

  • 0
class List {
  ListNode *head;
  ListNode *prev;
};

class ListNode {
  int data;
  ListNode *next;
  friend class List;
  ListNode(int d, ListNode *n) : data(d), next(NULL) {}
  void insertM(int d) {
    ListNode *ptr, *temp, *curr;
    ptr = head;
    while (ptr->data < d) {
      prev = ptr;
      ptr = ptr->next;
    } // end while
    temp = prev->next;
    curr = new ListNode(d, ptr);
    curr->next = prev->next; // or temp->next
    prev->next = curr;
    ;
  }
};

List mylist;

In this function, I’m trying to add a node in the middle of linked list. Other functions add items to the back and front just fine. When I add in the middle of the list, my prev->next links to curr just fine, but curr->next points to NULL.

I have been trying to make this program work for past 1.5 hours. I’ll appreciate your help. This is homework.

  • 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-03T17:25:14+00:00Added an answer on June 3, 2026 at 5:25 pm

    The general procedure you’ll want to use is:

    1. surf down the next pointers until you reach the node you want to insert after (call it A)
    2. change your inserted node (B)’s next pointer to match that of A’s next pointer
    3. change A’s next pointer to point to B

    It looks from your code that you’re trying to maintain a sorted list of integers. This being homework you probably won’t get a code snippet, but from glancing at your code, I have to ask why you take a next parameter in your node constructor, but then set the next value to null. Without seeing the rest of your code I can’t say for sure, but I’d change next(NULL) on line 9 to be next(n), and then remove the curr->next line near the bottom

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

Sidebar

Related Questions

int findLargest (ListNode *p) // -------------------------------------------------------------------------- // Preconditions: list head pointer is passed as
Write a class ListNode which has the following properties: int value; ListNode *next; Provide
Concerning data binding I have these classes: public class Foo : List<Bar> { public
i have repeated data in Target class list new TargetClass{ TID=102, ID=2, Adress=afff, Zip=222},
I am trying to implement a linked list for a data structures class and
public class Main { public static void main(String args[]) { List list = new
Some code for context: class WordTable { public: WordTable(); ~WordTable(); List* GetListByAlphaKey(char key); void
I am having problems saving serialized data from a nested custom class list. How
I have a ruby (1.9.3) on rails (3.1) app where: app/models/list.rb class List <
I have code that looks like this: template<class T> class list { public: class

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.