[Solved] CPP- I am getting Segmentation fault (core dumped)?

That’s why there are debug tools like gdb (just google for it 😉 ). This is the backtrace: #0 0x00000000004009ba in node::setnext (this=0x0, x=0x614cc0) at a.cpp:25 #1 0x0000000000400c18 in list::insertend (this=0x7fffffffdf10, x=45) at a.cpp:109 #2 0x00000000004008df in main () at a.cpp:137 that means in line 137 there is a function call (l.insertend(45)), then in line … Read more

[Solved] Linked list program for student average

Heading Hi, I have not looked thoroughly in the code . But , in a quick look I spotted the following basic problem nextPtr should be a pointer, you are creating an instance and copying the contents of the next structure. This is not efficient. I will declare it as below struct listNode *nextPtr; / … Read more

[Solved] My linked list code in c++ is only appending one value

Think very carefully about the code you have for stepping through the list looking for where you can append your new value, especially the last line inside that loop body: while(nodeptr->next){ nodeptr=nodeptr->next; nodeptr->next=newNode; } Were you to actually single-step your code through a debugger, examining the list after each statement, you would see the problem … Read more

[Solved] void struct linked list [closed]

This cannot work as void does not contain any member next. You must use your node structure struct tmpList * to access any members. Functions dealing with list manipulation should use the prope node type in the signature to get some type safety. If you really want to use void * in the signature, you … Read more

[Solved] Reverse a singly linked list in Java

There are 2 problems: you are not saving the new head once it is returned (when you reach the end of the list), so the returned head is always going to be the one of the first stack of recursion, which is the original first node; you are not assigning node.next to null on the … Read more

[Solved] If linked lists have many functional advantages over arrays, what advantages do arrays have over linked lists? [closed]

Because there is no free lunch. In general, if a data structure is more powerful than another, you will have to pay for that additional power somehow. Sometimes you will not be willing to pay that price. As for lists, you are correct, in terms of functionality, they are way better than arrays: You can … Read more

[Solved] How to choose proper if statements in linked list?

Consider the following Linked List: HEAD —> [“value2” | -]–> [“value3” | -]–> [“last_value” | null] Assuming current points to “value3”: HEAD —> [“value2” | -]–> [“value3” | -]–> [“last_value” | null] ↑ then current.next != null is true, since current.next is actually the “next” node. Now let’s assume current moved to “last_value”, now we’ll … Read more

[Solved] Insert linked list

In your Insert function, you never allocate newNode. Node* newNode; You need to allocate it like so: Node* newNode = new Node(); The program runs correctly after fixing this, and the output is: 24 http://ideone.com/16XL5W EDIT: Regarding your comment below, the following lines do not allocate anything: Node* newNode; struct Node* newNode; They are simply … Read more