linked-list

c linked list - is it possible to create a payload independent iterator function?

不打扰是莪最后的温柔 提交于 2019-12-24 17:46:01
问题 All, in my application I have a number of linked lists that are being created. For example one (struct record) holds the transcript text with several hundred nodes (lines of text), and a second type linked list (struct srch_results) holds search results from searching the first list with strstr(). There can be multiple lists of each within the application. The issue is I find myself recreating each forward/reverse iterator for each list type which is basically duplicating the code and

Hash table with linked list implementation and storing text file

混江龙づ霸主 提交于 2019-12-24 17:43:46
问题 I want to implement my own hash table using chaining and linked list but I am having a hard time figuring out how to use the implementation in the main method. I need to read a comma separated values file with data and store the names as keys and the two floating points as a value. I know I need to use object oriented programming but I having a difficult time accessing my data using my implementation. Here is my code: public class LinkedListHash{ String key; String value; LinkedListHash next;

How to access array of linked list?

[亡魂溺海] 提交于 2019-12-24 17:20:03
问题 I've created an array of LinkedList of Connection objects using the second answer from here. That is, I've done: LinkedList<Connection>[] map = (LinkedList<Connection>[]) new LinkedList[count]; However, I am confused as to how to access each element of the array (ie each LinkedList) and create a new node. Right now, I have: for (int j = 0; j < numOfConnections; j++) { map[j].add(new Connection(s.next(), s.nextDouble(), s.next())); } But I think this would only add a single new node to each

Implement an algorithm to find the kth to last element of a singly linked list

岁酱吖の 提交于 2019-12-24 17:13:38
问题 Implement an algorithm to find the kth to last element of a singly linked list. Is a good solution to the above problem, reversing the linked list then traversing again and getting the kth element? 回答1: First of all the list is singly-linked . So that is a good hint that you should not try to reverse it, because you would need as much storage to make the copy. You can use a modified version of the turtle-hare algorithm: Use a hare pointer at the start of the list Move it at least K elements

linux x64 c++ allocates way too much memory for a linked list; why?

﹥>﹥吖頭↗ 提交于 2019-12-24 17:09:18
问题 i will be using linked list example code seen here on stackoverflow to illustrate the problem. my c++ written progam (x64) contains this linked list code : old code snippets deleted; im sorry if comments doesnot make sense anymore. added fully working code to show what my problem is. compile : g++ linkedlist.cpp -o linked-list #include <cstdlib> #include <iostream> using namespace std; struct node { public : unsigned int part1; // 4 bytes unsigned int part2; // 4 bytes node *next; //pointer,

A method to print linked list in reverse/backward order in python

孤街浪徒 提交于 2019-12-24 16:13:51
问题 I'm writing a class called LList and in the class I defined a couple of methods. I am having issue with writing a method to print the linked list in backward order. class Node(object): def __init__(self, data=None, nextNode=None): self.data = data self.nextNode = nextNode class LList(object): def __init__(self, head=None): self.head = head self.size = 0 def insert(self, node): if not self.head: self.head = node self.size += 1 else: # set new nodes pointer to old head node.nextNode = self.head

Linked List Data All The Same

谁说胖子不能爱 提交于 2019-12-24 14:08:13
问题 I'm trying to read in input from a .txt file, and add it into a singly linkedlist. The problem I'm having is the Nodes are being created and connected correctly (I'm getting the correct length), but after adding all the Node, each Data field is the same. I was wondering what the problem is, and how to fix it. Been going at it for awhile! Add Function: #include "linkedList.h" #include <stdlib.h> #include <string.h> void addOrdered(Node ** Head,char * input) { printf("\nInput: %s\n",input);

What is a better method to sort strings alphabetically in a linked list that is reading in lines from a text file?

…衆ロ難τιáo~ 提交于 2019-12-24 13:56:00
问题 public class ContactList { private ContactNode head; private ContactNode last; public ContactNode current; public ContactList value; public ContactList() {} public void addNode(ContactNode input) { if (this.head == null) { this.head = input; this.last = input; } else last.setNext(input); input.setPrev(last); this.last = input; } public void traverse() { System.out.println(); current = this.head; while (current != null) { System.out.print(current.getName() + " "); System.out.println("");

Saving object with linkedlist - error on API 10

不想你离开。 提交于 2019-12-24 13:24:50
问题 when saving an object with LinkedList on android API 10 I obtain an error: 08-10 14:37:45.091: E/AndroidRuntime(29845): FATAL EXCEPTION: Thread-17 08-10 14:37:45.091: E/AndroidRuntime(29845): java.lang.IllegalArgumentException: no char field 'exponential' 08-10 14:37:45.091: E/AndroidRuntime(29845): at java.io.EmulatedFields.put(EmulatedFields.java:459) 08-10 14:37:45.091: E/AndroidRuntime(29845): at java.io.EmulatedFieldsForDumping.put(EmulatedFieldsForDumping.java:83) 08-10 14:37:45.091: E

java.lang.ClassCastException: Creating a synchronized Linked List

半腔热情 提交于 2019-12-24 13:00:21
问题 I want a synchronized LinkedList with a Generic Class A, here the relevant parts: public abstract class A<T extends B> implements Runnable { And the interface for B, where the "real" B, will be a supclass public interface B{ Following setup will throw a runtime error: LinkedList<A<? extends B>> eopList = (LinkedList<A<? extends B>>) Collections .synchronizedCollection(new LinkedList<A<? extends B>>()); I've found the following proposal, but it also won't compile: LinkedList<A<? extends B>>