Ask your own question, for FREE!
Mathematics 15 Online
OpenStudy (anonymous):

Hello! I'm working on a C++ assignment and I was wondering if there is any Math Majors out there that can help me with this. I'll post my question below with more details and I will give a medal to the best response.

OpenStudy (anonymous):

Hello, I'm working on a C++ program and I'm trying to create an insert function that alphabetizes a linked list. Here's my code for my insert function: void insert(word* node, word* newNode){ // insert newNode after node newNode->next = node->next; node->next = newNode; newNode->previous=node->previous; newNode->previous=node; } Here's my code inside my int main(): for(int i=1;i<size;i++){ for(word* w=startOfList;w!=NULL;w=w->next){ if(wordss[i].name<wordss[i+1].name){ insert(&wordss[i], &wordss[i+1]); } } } My next and previous pointers are not pointing to anything and I'm not sure why? If more information is needed on my code I will provide it. The arrays are taking in string words from a linked list. Any help is appreciated Thank you!

OpenStudy (mathmate):

Wrong place to post, but here's an answer anyway: Was: A -> B becomes A-> newNode -> B newNode->next = node->next; // ok newNode->next =B node->next = newNode; // ok A->next = newNode newNode->previous=node; // newNode->previous = A newNode->next->previous = newNode; // B->previous = newNode You'll get better response from Computer Science Group.

geerky42 (geerky42):

He tired that. http://openstudy.com/study#/updates/53938ba2e4b01c619df0e006

geerky42 (geerky42):

Math subject is the most active subject on Openstudy haha

OpenStudy (mathmate):

If you still get null pointers, check that "node" is not null before doing anything. Also check that special arrangements need to be made for the beginning and end of list.

OpenStudy (mathmate):

@geerky42 Guess you're right!

OpenStudy (anonymous):

Yes I realized that it is the most active haha. I'm just trying to understand the code right now and then I'm going to check if I can get it to work. I'm still not sure how to go about the special conditions at the end but I'll see what I can do. Thank you all very much!

OpenStudy (mathmate):

You're welcome!

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!