linked-list

Inserting Node at the beginning of a linked list

こ雲淡風輕ζ 提交于 2019-12-12 00:37:20
问题 I have to insert a new Node at the beginning of my linked list. After I switched the Data Packages I try to overwrite the Data of my first Node with the new Data. But if I do that, my Program changes the data-values of my first and second Node. void insert(String iv_name, String iv_name_first, String iv_title, int iv_earning) { if (this.first == null) { this.first = new Node(new Data(iv_name, iv_name_first, iv_title, iv_earning, 0)); } else { Node n = this.first; Data last_n_data = getLast()

Implementing Selection Sort for Linked Lists

不问归期 提交于 2019-12-12 00:27:31
问题 I am trying to implement a selection sort algorithm that will work with linked lists and will use iterators to scrool through them. The selection sort algorithm is the following: for each element of the list except the last one(let's call it K ), it will seek out the smallest on from the position we are currently on(so it will start from K until the last element). After that it will swap K and the smallest element. I think that my mistake is in the first for loop; I am very unsure that --a

Add nodes in linked list

安稳与你 提交于 2019-12-12 00:18:20
问题 Trying to implement single-linked-list in below program, i am really not able to undertsand how to add a node in an Linked list (for start, m trying it on empty linked list ). To put it plain simple,i tried to setData and setNext but getSizeofList() return 0 everytime....its really looking like a rocket science to me now!! Question : Can some-one tell me how to implement it....or rather, add a node to existing linked list.... What i have tried so far and why they dint worked out: i referenced

Insertion sort linked list c++

梦想与她 提交于 2019-12-12 00:09:41
问题 I'm trying to sort a filled linked list with random numbers. The function I have made doesnt work as it should. I can't see what is wrong, its not sorting the numbers properly. void linked_list::SortList() { if(is_empty()) { return; } for(node_t *it =head; it!=tail; it = it->next) { int valToIns = it->value; node_t *holePos = it; while(holePos->prev && valToIns < it->prev->value) { holePos->value = holePos->prev->value; holePos = holePos->prev; } holePos->value = valToIns; } } 回答1: You're

substring() method for linked list object

ε祈祈猫儿з 提交于 2019-12-11 23:53:17
问题 I'm having some trouble writing a substring() method for a class I'm building called LString . This class creates a linked list object called LString that builds strings. It mimics the String and StringBuilder objects in Java. substring(int start, int end) creates a new LString out of the given this LString, from the index provided by start to end . It returns type LString . Here is the error message without any edits to make end inclusive: Running substring tests (63 tests) Starting tests: .

Cannot delete vowels from singly linked list

霸气de小男生 提交于 2019-12-11 23:45:00
问题 I am having an issue while deleting the vowel from a linked List. The program accept command line arguments, combines them in a single string and add each character to a linked list as node. When i try to run the program with command line argument "lemon", the successfully deletes the vowels. i.e the program deletes the vowels successfully if the argument doesn't contain consequetive vowels. On the other hand, if i try to do the same with command line argument "aeiou", the program crashes

Inserting a name and number to the end of linked list

大憨熊 提交于 2019-12-11 23:44:23
问题 My text file reads like this: George Washington, 2345678 John Adams, 3456789 Thomas Jefferson, 4567890 James Madison, 0987654 James Monroe, 9876543 John Quincy Adams, 8765432 Andrew Jackson, 7654321 Martin Van Buren, 6543210 Can someone offer insight on how I get my insert function to add the name and ID number to the end of the linked list? When I run the code an select option 1 it skips over the add name and only asks to enter the integer. After that nothing happens. #include <stdio.h>

Preventing char * in linked list from changing

倾然丶 夕夏残阳落幕 提交于 2019-12-11 23:39:03
问题 Okay, so in my program, I have a main function in which I input a character string into a buffer (char buffer[20]). It passes this as a char * to a function that creates a linked list struct, sets the struct's char * value equal to the input text char * and then returns the struct pointer and puts it at the front of my list. Now when I put in another character string to make another linked list struct, it sets the char * value of BOTH the structs to the text I just put in. How can I make it

Returning sum of values in linked list

百般思念 提交于 2019-12-11 23:37:33
问题 I have the following code: int sum(LinkedList * list) { assert(list!=NULL); Node *currentNode = list->head; int sum = 0; for (currentNode = currentNode->next; currentNode !=NULL; currentNode = currentNode -> next) { sum = sum + currentNode->data; } return sum; } I want it to return the sum of all the values in the linked list *list. However, I keep getting a segmentation fault. Can anyone help me spot the fatal error? 回答1: Change your loop to: for (currentNode = list->head; currentNode !=NULL

Undo/redo functionality with LinkedList<Action> implementation

一笑奈何 提交于 2019-12-11 23:32:26
问题 I am writing my own 'Rubik's cube' application. The main class Cube has 18 rotation methods: RotateAxisXClockWise, RotateAxisXAntiClockWise RotateAxisYClockWise, RotateAxisYAntiClockWise RotateAxisZClockWise, RotateAxisZAntiClockWise RotateUpperFaceClockWise, RotateUpperFaceAntiClockWise RotateFrontFaceClockWise, RotateFrontFaceAntiClockWise RotateRightFaceClockWise, RotateRightFaceAntiClockWise RotateBackFaceClockWise, RotateBackFAceAntiClockWise RotateLeftFaceClockWise,