linked-list

inserting in a sorted linked list in Java

Hi stack overflow. I need to insert some objects contained in a Node class into a LinkedList class in a sorted over. The Node class looks like: public class Node { private Card val; private Node next; public Node(Card v) { val = v; next = null; } where card implements the Comparator interface. I'm trying to...

atomic swap with CAS (using gcc sync builtins)

Can the compare-and-swap function be used to swap variables atomically? I'm using C/C++ via gcc on x86_64 RedHat Linux, specifically the __sync builtins. Example: int x = 0, y = 1; y = __sync_val_compare_and_swap(&x, x, y); I think this boils down to whether x can change between &x and x; for instance, if &x constitutes an op...

Recursion in assembly?

I'm trying to get a better grasp of assembly, and I am a little confused about how to recursively call functions when I have to deal with registers, popping/pushing, etc. I am embedding x86 assembly in C++. Here I am trying to make a method which given an array of integers will build a linked list containing these integers in the order...

Can anyone would provide me an example of reference-based linked list?

I'm trying to create a reference based linked list anyone would be able to provide me an example of it?? ...

When to use () with classes?

This is really starting to confuse the hell out of me. When do I use them, when don't I? For example I was reading a .cpp on linked lists whose class declaration was: struct CarPart { long PartNumber; char Partname[40]; double UnitPrice; CarPart *next; }; class ListOfParts { int size; public: CarPart *head; ...

Why are Stack<T> and Queue<T> implemented with an array?

I'm reading C# 4.0 in a Nutshell by the Albahari brothers and I came across this: Stacks are implemented internally with an array that's resized as required, as with Queue and List. (pg 288, paragraph 4) I can't help but wonder why. LinkedList provides O(1) head and tail inserts and deletes (which should work well for a stack or qu...

How to determine whether a linked list contains a loop?

Possible Duplicates: find whether a loop in a linked list without two pointers How to determine if a linked list has a cycle using only two memory locations. Best algorithm to test if a linked list has a cycle During a preparation for a job interview, I encountered the following question: How can you determine whether a l...

Using C++ is a Linked-List implementation without using pointers possible or not?

My question is very simple, can one using C++, implment a link-list data structure without using pointers (next nodes)? To further qualify my question, I'm mean can one create a Linked-List data structure using only class instantiations. A common node definition might be like so: template<typename T> struct node { T t; node<T>* n...

I'm new to C++. Please Help me with the Linked List (What functions to add)?

DEAR All; Hi, I'm just beginner to C++; Please help me to understand: What functions should be in the Linked list class ? I think there should be overloaded operators << and >>; Please help me to improve the code (style, errors, etc,) Thanks for advance. Igal. Edit: This is only first sta...

Item in multiple lists

So I have some legacy code which I would love to use more modern techniques. But I fear that given the way that things are designed, it is a non-option. The core issue is that often a node is in more than one list at a time. Something like this: struct T { T *next_1; T *prev_1; T *next_2; T *prev_2; int value; }; t...

Wanted: Very Fast Linked Lists in C

I am trying to implement a singly linked list in C. A common implementation that you see floating around the internet is something like typedef struct { int head; Node *tail; } Node; with methods like Node cons(int head, Node tail) { Node y; y.head = head; y.tail = malloc(sizeof(Node)); *y.tail = tail; } Performance is ...

Odd linked list/anonymous class behavior - executing when added?

This question is related to How to Queue and Call Actual Methods... Anyway, I've decided to (after all) go with the anonymous class idea. The problem is that when I ADD my anonymous class to the linked list, it's actually calling execute() immediately... and it shouldn't be. Execute() is to be called later. Anyway, this is what I have: ...

Linked-list representation of disjoint sets - omission in Intro to Algorithms text?

Having had success with my last CLRS question, here's another: In Introduction to Algorithms, Second Edition, p. 501-502, a linked-list representation of disjoint sets is described, wherein each list member the following three fields are maintained: set member pointer to next object pointer back to first object (the set representative...

Understanding a Linked List

The Following code is used as an example as an into to Generics. // type parameter T in angle brackets public class GenericList<T> { // The nested class is also generic on T private class Node { // T used in non-generic constructor public Node(T t) { next = null; data = t; ...

simulate a Three-State process model (ready, running and blocked) and a simple process control block structure

program will read input and directives from a file. The input describes a time sequence of events that occur. These are the full set of events you will simulate: cpu - The processor runs for 1 time step the currently running process new - A new process is created done - The currently running process has finished wait X - T...

Cyclical Linked List Algorithm

I have been asked recently in a job interview to develop an algorithm that can determine whether a linked list is cyclical. As it's a linked list, we don't know its size. It's a doubly-linked list with each node having 'next' and 'previous' pointers. A node can be connected to any other node or it can be connected to itself. The only s...

Problem either adding to or traversing a linked list

I have a problem either adding to or traversing a linked list. The main item class is used by another class but I can add the correct number of these but it looks like when I add more data to the list the app no longer works. I am not sure exactly where the error is. I know that when I try to traverse the list the application crashes. A...

Link lists in C++

Hey guys, sorry for, but I'm new to doubly-linked lists and was wondering if anyone could tell me why my program crashes when i use add_end()? #include <iostream> using namespace std; node *start_ptr = NULL; node *current; int option = 0; void add_end() { node *temp, *temp2; temp = new node; cout << "Enter name: ...

Link lists in C++ (pt. 2)

How come void del_begin() crashes when there's only one node left (I have other functions to add nodes)? #include <iostream> using namesspace std; node *start_ptr = NULL; node *current; int option = 0; void del_end() { node *temp, *temp2; temp = start_ptr; if (start_ptr == NULL) cout << "There are no nod...

trouble using ListIterator for a LinkedList in java

Is it possible to iterate through a LL in Java using a ListIterator, add objects periodically to the list, and process these items in the list in the order they were added? Let's say I start with a LL with a single object in it. I process this object, and decide I want to add two additional objects, which I want to further process (lik...