linked-list

Saving from a linked list to a file and loading it back

怎甘沉沦 提交于 2019-12-12 04:02:56
问题 I'm having trouble loading from a file into a linked list, been trying the whole day first of all this is my struct typedef struct Sensor { int id; int intervalo; char local[30]; char tipo[30]; //bool active; int active; struct Sensor* anterior; struct Sensor* proximo; } Sensor; this is my save function which i think its working fine, since the file gets created and the content is there. void gravaLista(Sensor* l) { FILE *ficheiro; Sensor* temp = l; ficheiro = fopen("sensores.txt", "r+t"); if

java random generator without repeat

好久不见. 提交于 2019-12-12 03:56:05
问题 Im trying to generate a 2d array using a random generator. basically, each column should contain a random value between 1-50 that is not repeated but the problem is, I can't get a repeat value on the same row, or any other row or column in the program. In other words, each I integer should only display once. My objects were created via linked list and I will probably integrate the algorthim in there once I figure it out but for now, heres what I did. int[] array = new int[50]; for(int i=1;i<

converting sorted linked list to balanced binaryTree not returning correctly?

馋奶兔 提交于 2019-12-12 03:45:42
问题 Here are key methods I wrote for converting linkedList to Balanced BinarySearch Tree . I get BST but it is not balanced. why is it so? public static Node headNode; public static IntTreeNode convertLinkedListToBST(Node node){ int len = getCount(node); headNode = node; return convertLinkedListToBSThelper(node, 0, len-1); } //http://www.programcreek.com/2013/01/leetcode-convert-sorted-list-to-binary-search-tree-java/ public static IntTreeNode convertLinkedListToBSThelper(Node node, int start,

Linked List class not inserting Nodes when called from another class method

两盒软妹~` 提交于 2019-12-12 03:34:23
问题 I have an iObj class that take two parameters in its constructor, this object is then passed to another method(Add) of another class(store) that takes object from iObj and stores it in a Linked List (List). The Linked list has a class of its own. When I run main like this Store st; st.Add(iObj(Britain", 1)); st.Add(iObj(Germany", 0.01)); st.Add(iObj(Bhutan", 10)); st.PrintStore(); Nothing is displayed on the screen. List Implementation. List::List() { head = NULL; } void List::insert(iObj*

Sample program involving linked lists and structs doesn't work [closed]

对着背影说爱祢 提交于 2019-12-12 03:28:47
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . So, this is a sample program supplied by my prof. Its function is to search a linked list of trees and return a result of weather or not it found the tree input by the user. However, no matter what I input it always returns false. What's wrong with it? #include <stdio.h> #include <string.h> #define NL 20 typedef

Doubly linked list and how to move the iterator to the next node

為{幸葍}努か 提交于 2019-12-12 02:52:33
问题 I have to build a Deque list and inside the the Deque list, it has a function call find, to find the value inside the list. But I'm having problem to try to move the iter over to the next node if that node does not contain the value that I am searching for. Her is the snippet of my find function: unique_ptr<DequeIterator<E>> find(E match) { assert(!is_empty()); bool is_found = true; // set the pointer point to the first node from the beginning unique_ptr<DequeIterator<E>> iter(iter_begin());

Need help writing a method that adds 2 polynomials together (v2)

北战南征 提交于 2019-12-12 02:41:36
问题 Background: I am currently working on writing a method that adds two polynomials (given by 2 text files) together. So for example: 4.0x^5 + -2.0x^3 + 2.0x + 3.0 & 8.0x^4 + 4.0x^3 + -3.0x + 9.0 would result in: 4.0x^5 + 8.0x^4 + 2.0x^3 - 1.0x + 12 Currently, my output only produces: 8.0 x^4 + 4.0x^5 + 2.0x^3 - 1.0x + 12 -- this is because of the order of my for loops which you can see below. I need the terms to be in order. Polynomial answer = new Polynomial(); //p = addZeroes(p); for (Node

Extracting Information from Streams and Saving in LinkedList

ぃ、小莉子 提交于 2019-12-12 02:22:18
问题 I have created a server that uses threads to allow multiple nodes to connect and when they connect the server receives the nodes information and stores it to a linked list. The problem I'm having is that when the node connects to the server, the information is retrieved but will not store in the list. Instead of stating the information requested, Current nodes connected: loadbalancer.NodeList@77c57d28 is shown. Any help would be fantastic. Thanks. Below is the linkedlist, saved as NodeList:

Reversing first K nodes of Linked List,Why recursion executing twice for last iteration

£可爱£侵袭症+ 提交于 2019-12-12 02:13:55
问题 While solving the problem that reverse first K elements of linked list i have written the below recursive code but the last iteration executing twice i.e for k=1, function call reverseNode() happening twice. Can any body why it happening like that. Please correct me if i did any thing wrong in it. Example : If input is 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8 and k = 4 then output is 4 -> 3 -> 2 -> 1 -> 5 -> 6 -> 7 -> 8 public void reverseListRecursion(int k) { this.reverseNode(null, headNode,k);

c++ linked list missing nodes after allocation in multiple threads, on x64 linux; why?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-12 02:07:57
问题 I've included a source code you can compile and see the problem for yourself. compile with g++ -lpthread list-memchk.cpp -o list-memchk RUN THIS, FOR EXAMPLE, ./list-memchk 43000000 30000000 10 ive included three files, first one, list-memchk.cpp #include <cstdlib> #include <iostream> #include <pthread.h> using namespace std; struct node { public : unsigned int part1; // 4 bytes unsigned int part2; // 4 bytes node *next; //pointer, 8 bytes on 64 bit system unsigned int read_part1(); }; struct