linked-list

why linked list are not sorted?

回眸只為那壹抹淺笑 提交于 2021-02-10 05:32:25
问题 I try to make linked list for string and sort with their score but my sorting algorithm is doing nothing. Thank you for any advice and help. void SortList(Linked_List *list) { Node *temp, *index = NULL; temp = list->head; int tmp; if (list->head == NULL) { return; } else { while (temp != NULL) { index = temp->next; while (index != NULL) { if (temp->score > index->score) { tmp = temp->score; temp->score = index->score; index->score = tmp; } index = index->next; } temp = temp->next; } } } here

Append linked list with recursion

萝らか妹 提交于 2021-02-08 10:40:45
问题 I want an insert function that calls a private recursive insert function that adds the next number to the end of a linked list. I am having trouble on which parameters I should use and what should be in the recursive insert function. I am thinking that the recursive insert function needs a Node pointer to step through recursively. class LinkedList{ private: struct Node{ int data; //stores data in nodes Node* next; ~Node(){delete next;} }; public: LinkedList(){ first = NULL;} ~LinkedList()

Traversing a single linked list in order

情到浓时终转凉″ 提交于 2021-02-08 10:33:33
问题 I have been trying to think a way to traverse a single linked list. This is so far what I have done: #include <iostream> typedef struct node { int data; // will store information node *next; // the reference to the next node }; int printList(node *traverse) { if (traverse->next == NULL) { return -1; } traverse=traverse->next; printList(traverse); cout << traverse->data << endl; return 0; } int main() { node *head = NULL; for (int i = 0; i < 10; i++) { node *newEntry = new node; newEntry->data

Remove node from linked list recursively

和自甴很熟 提交于 2021-02-08 10:20:55
问题 Given the head of a linked list and the int to search for as parameters, I need a method that will remove the first occurrence of this number in the list, and return the modified list. however i cannot modify the original list. I know how to remove the node from the list, but im not sure how i would keep the original list intact since this has to be done recursively. below is the method ** initially M is the original list. I dont know that it will still be the same list after calling the

Creating linked list of strings

匆匆过客 提交于 2021-02-08 08:37:15
问题 I am new to data structures as well as to linked lists. I am working on project named as Amazon product availability checker using tree in C . So I want to store strings in each node of the tree but while storing strings the code is not showing any error but the output is also not getting printed. I have pass the node to print function to print the string but nothing is getting printed. I have shared the code for one string and one node only. I am working on ubuntu and I am coding in the C

Can I delete a memory previously allocated dynamically, but with a different pointer?

纵然是瞬间 提交于 2021-02-08 07:22:08
问题 I was making a program for linked list in C++. To implement the concept, I created a pointer 'start' globally, pointing to the first element of the list. After completion of the program I tried to delete all memory allocated dynamically to prevent memory leaks, by accessing successive nodes using the start and another locally declared pointer 'p'. Here, I used a pointer pointing to the same correct addresses, but this pointer was not the one used for memory allocation, but was declared

Sentinel approach with Doubly Linked List

家住魔仙堡 提交于 2021-02-08 06:36:36
问题 I am going through the doubly linked list in Java, I am reading about Sentinels in the doubly linked list from Book. Which states that In order to avoid some special cases when operating near the boundaries of a doubly-linked list, it helps to add special nodes at both ends of the list: a header node at the beginning of the list, and a trailer node at the end of the list. These “dummy” nodes are known as sentinels (or guards), and they do not store elements of the primary sequence What are

Dummy Head Node Linked List

拥有回忆 提交于 2021-02-07 19:45:32
问题 I'm trying to write an insert function for string values for a circular doubly linked list. I saw that creating a dummy node is beneficial in doing this so I can eliminate special cases like when the list is empty. The problem is I'm not finding alot of good information on dummy head nodes. I understand their purpose, but I don't understand how I create/implement it. appreciate all the code examples guys, tried to figure it out on my own getting a little stuck though if someone can look at it

How do I reference an Array element in a List of Arrays?

梦想与她 提交于 2021-02-07 19:36:21
问题 I have created a LinkedList of String arrays: public static void main(String[] args){ String[] one = new String[10]; String[] two = new String[10]; String[] three = new String[10]; LinkedList<String[]> myList = new LinkedList<String[]>(); myList.add(one); myList.add(two); myList.add(three); } My question is how do I now access an element of one of the arrays. For instance, I can access (or in the example print) the entire array element via: System.out.println(myList.get(0)); But how do i

Error deleting node from first position in c

ⅰ亾dé卋堺 提交于 2021-02-07 11:11:06
问题 As my many previous posts show, I am making a code to simulate a crazy 8's card game. I have a delete node function that is meant to delete the card from the deck being played. It works for cards after the first, but every time i try to delete the first card (node) from the list it will not delete and then messes up the whole program after it. Here is the function: void deleteNode(card *head, int coordinate) { card *current = head; card *temp = NULL; temp = current; int count = 1; while (head