102
голосов
26ответов
42365 просмотров

Check if two linked lists merge. If so, where?

This question may be old, but I couldn't think of an answer. Say, there are two lists of different lengths, merging at a point; how do we know where the merging point is? Conditions: We don't know the length We should parse each list only once.

1
голосов
4ответов
1352 просмотров

Which Java collection's Linked list adds in O(1) when given an element?

i need to insert into a very large LinkedList, whose elements i hold in a fast-access HashMap. it's important to keep the list in order (which is not the natural order of the keys). i thought it would be possible to hash the linked list nodes, then insert directly on the node (getting the node f...

0
голосов
3ответов
1893 просмотров

What is test best sorting algorithm for a Doubly LinkedList

Can someone recommend me a sorting algorithm for my custom link list + example, basically it is similar to the Generic LinkedList so if you could give examples for the Generic LinkedList it will be great. I am planning to implement the merge sort, please advice on the pros/cons as I am not so fa...

1
голосов
5ответов
2852 просмотров

Most optimal way to find the sum of 2 numbers represented as linked lists

I was trying to write a program for the problem I mentioned above, the numbers (i.e the lists) can be of unequal length, I was not able to figure out a way to do this other than the most commonly thought of approach i.e reverse list-1 reverse list-2 find the sum and store it in a new list rep...

0
голосов
3ответов
173 просмотров

Counting memory blocks

This is a homework question from compiler design course. I just need an explanation of certain parts of the question. It is claimed that returning blocks to the standard memory manager would require much administration. Why is it not enough to have a single counter per block, which hold...

5
голосов
3ответов
1847 просмотров

Clearing a double-linked list

I have a double linked list (queue) I have made on my own. I am wondering, to clear the linked list, is it enough to simply remove the head and tail references? E.g public void Clear() { Head = null; Tail = null; } I am imaging a domino effect, but I am having a hard time testing it...

4
голосов
2ответов
570 просмотров

Test Suite for a Linked List Implementation? (and/or other data structures)

For fun, I'm going to write my own implementations of common data structures like Linked List or Binary Sorted Tree. Are there any good test suites that already exist that I can use to make sure they are fully living up to their contracts? (It probably wouldn't be that hard to test them myself, ...

0
голосов
2ответов
628 просмотров

Paint component doesn't print polygon according to intended coordinate

I have problem drawing the triangle polygons based on the coordinates which are stored in linked list. When I checked the linked list elements using System.out.println in paint component method Public void paintComponent (Graphics g) { ... for (Polygon p : triangles) { g2.drawPolygon(t...

1
голосов
3ответов
5184 просмотров

Operator Overload &lt;<in linked list></in>

How can I overload the operator &lt;&lt;. The purpose of the overloaded operator is to do: cout &lt;&lt; ptr-&gt;info and not receive the memory address but Display the maker year and model of that node's info section. Example: template &lt;class DataType&gt; struct Node { DataType info; Node&l...

7
голосов
10ответов
1243 просмотров

Is it possible to create a linked list on the stack in C++?

I just started learning C++ couple of weeks ago. So now I have this school assignment problem that asks me to implement a linked-list without using "new" or anything to do with dynamically allocating memory (and cannot use any ADT from STL). The prof says that everything can be done on the stack,...

0
голосов
3ответов
119 просмотров

Why can't the Nodes be linked together?

EDIT: Is it possible to NOT use new? (do not dynamically allocating memory) I think it is push that is wrong, but I don't know where, how, and why. here is the code: struct Node { string fileName; Node *link; }; int size(Node *&amp;flist) { int count = 0; Node *tempPtr = flist; ...

0
голосов
2ответов
1485 просмотров

Java: Trouble with TreeSet and LinkedList

I have an unsorted linked list. To sort it, I thought I'd put the values into a TreeSet with a comparator supplied, then return those values as a new linked list. Yet, it fails. Comparator: public class SortSpeciesByCommonName implements Comparator&lt;Species&gt; { /** * a negative in...

1
голосов
3ответов
12656 просмотров

return a list<int> from a function c++</int>

Every time I try to use my add function and return a list from it. I get an undefined symbol error. What am I doing wrong here. this is the error: Undefined first referenced symbol in file add(std::list&lt;int, std::allocator&lt;int&gt; &gt; c...

0
голосов
3ответов
236 просмотров

Why is this string changed?

I have the following code, so far, I want to check if a file name is already in the linked list fileList (or flist). according to the output, the string saved in the first Node was changed somewhere in Node* getFileName(Node *&amp;flist) How did this happen? Also, is there anything else that I'm ...

2
голосов
4ответов
16169 просмотров

Java How to find a value in a linked list iteratively and recursively

I have a method that has a reference to a linked list and a int value. So, this method would count and return how often the value happens in the linked list. So, I decided to make a class, public class ListNode{ public ListNode (int v, ListNode n) {value = v; next = n;) public int value; pub...

26
голосов
14ответов
30236 просмотров

detecting the start of a loop in a singly linked link list?

Is there any way of finding out the start of a loop in a link list using not more than two pointers? I do not want to visit every node and mark it seen and reporting the first node already been seen.Is there any other way to do this?

3
голосов
3ответов
8677 просмотров

Issue calling a MySQL stored procedure (with params) via a linked server (SQL Server 2005) using OPENQUERY syntax

I'm having issues when trying to call a MySQL (5.0.77) stored procedure with parameters, via a linked server (SQL Server 2005) using the OPENQUERY syntax. The MySQL stored procedure returns a result set, and when I use the 'EXEC ... AT ...' syntax the call works fine, e.g... EXEC('CALL my_store...

6
голосов
8ответов
43365 просмотров

Swapping Nodes on a single linked list

I am trying to make a swapNode function that can take any two nodes and swap them. I've made an algorithm that works if they're at least 2 nodes away, but I can't seem to come up with an algorithm that will work if they are closer to each other. Here's what I wrote so far: void swapNode(call * ...

96
голосов
13ответов
134706 просмотров

What's the fastest algorithm for sorting a linked list?

I'm curious if O(n log n) is the best a linked list can do.

0
голосов
7ответов
4024 просмотров

traversing a singly linked list in C++

I was wondering if it is possible to traverse a linked list like this: currentNode = randomNode;//where randomNode may or may not = firstNode prevNode = firstNode; while(prevNode != currentNode &amp;&amp; prevNode-&gt;link != currentNode) { prevNode = prevNode-&gt;link; } Is it possible t...

0
голосов
3ответов
2394 просмотров

Linked list and copy constructor

I'm trying to write a basic, singly-linked list class in C++. I did it in my data structures class years back, but I can't remember the details. Should my Node class have a copy constructor? It has a Node* as a member variable, and as far as I know you're always supposed to write a copy construc...

0
голосов
2ответов
1336 просмотров

List Linked List reference

How to get the data reference/index in Linked list? e.g. if I have this linked list java.util.List&lt;Polygon&gt; triangles = new LinkedList&lt;Polygon&gt;(); polygon triangle, selectedTriangle; Point startDrag,endDrag,midPoint; .... triangles.add( new Polygon(xs, ys,3)); e.g. How can I...

1
голосов
3ответов
6977 просмотров

How to remove specific element on List

How to remove specific element on List? ... java.util.List&lt;Polygon&gt; triangles = new LinkedList&lt;Polygon&gt;(); Point startDrag, endDrag, midPoint; Polygon triangle; .... int[] xs = { startDrag.x, endDrag.x, midPoint.x }; int[] ys = { startDrag.y, startDrag.y, midPoint.y }; triangle...

6
голосов
5ответов
7040 просмотров

Visual Explanation Guidance needed for reversal of Linked List datastructure code?

I have following piece of code for reversing the linked list. I am getting confused in while loop and so would certainly appreciate if someone can provide visual explanation of how actually it's working. static void Reverse (struct node** headRef) { struct node* result = NULL; struct...

4
голосов
2ответов
11437 просмотров

traversing task_struct-&gt;children in linux kernel

I am trying to traverse a task_struct's children in the linux kernel and get information from the children. I'm having problems with all the information, so let's just keep it at the getting the pid for simplicity. This is the relavant part of my code. struct list_head * p; struct task_struct t...

6
голосов
4ответов
7760 просмотров

Count number of nodes in a linked list that may be circular

Here is the problem, it is from Sedgwick's excellent Algorithms in Java (q 3.54) Given a link to a node in a singly linked list that contains no null links (i.e. each node either links to itself or another node in the list) determine the number of different nodes without modifying any of the nod...

4
голосов
13ответов
27785 просмотров

Remove node from single linked list

as far as I can see, you can do: Find the node to remove. node.previous.next = node.next node.next.previous = node.previous node.previous = null node.next = null Dispose of node if you're in a non-GC environment If your list is a double linked. But how do you do it with a single linked list?...

0
голосов
7ответов
925 просмотров

Reverse a single chained List

I hope I am using the right terminology. I have made a single-chained list. class MyStack { public Node Initial { get; set; } public MyStack() { Initial = null; } public void Push(int data) { var node = new Node { Data = data, Next = Initial }; I...

2
голосов
2ответов
163 просмотров

linkedlist which links to itself?

Is there a name for a linked list type structure where the head and tail nodes link to each other? In such a list you can obviously iterate through it forever as it double backs on itself.

-1
голосов
3ответов
427 просмотров

How do I use linkedlists for java?

I need to use a LinkedList to add cells of a prison with the cell numbers 1.1, 1.2, 1.3, 1.4 etc. There are two levels and odd numbered cells have 1 bunk whereas even numbered cells have 2 bunks. How can I do this? I did this to create a linkedlist. That is in my Cells class and I have 2 child c...