linked-list

Some help with a Linked lIst

Okay I have updated my code quite a bit. I am getting a new problem, but it seems to be on a correct path. Now when I enter in the numbers it just continually spits out the first number I entered instead of moving to the next number. main.c #include <stdio.h> #include <stdlib.h> #include <stdbool.h> #include <cType.h> #include "list.h"...

Comparing two LinkedList<String> with ListIterator versus for loop and get(int index)

I have two LinkedList objects that are always of the same size. I want to compare them to see if they are identical in content. What are the general performance and style implications of creating a ListIterator for each list and using a while hasNext loop versus using a counter (int i) and iterating from 0 to linkedlist.size() using li...

Linked list traversal, compiler's symbol table and duplicate identifier checks

My "textbook" goes: a) Obj p = curScope.locals, last = null; while (p != null) { if (p.name.equals(name)) error(name + " declared twice"); last = p; p = p.next; } if (last == null) curScope.locals = obj; else last.next = obj; Should I refactor along these lines? b) if (curScope.locals == null) { curScope.locals = obj; } e...

find whether a loop in a linked list without two pointers

find whether there is a loop in a linked list. Do you have other ways instead of using a quick pointer and a slow pointer? ...

LinkedList: remove an object

Is this a valid way to find and remove item from a LinkedList in Java using a for each loop, is it possible that inconsistency may arise: for(ObjectType ob : obList) { if(ob.getId() == id) { obList.remove(ob); break; } } ...

Finding the "Nth node from the end" of a linked list.

This seems to be returning the correct answer, but I'm not sure if this is really the best way to go about things. It seems like I'm visiting the first n nodes too many times. Any suggestions? Note that I have to do this with a singly linked list. Node *findNodeFromLast( Node *head, int n ) { Node *currentNode; Node *behindCu...

Merging two sorted lists

Hi, This is one of the programming questions asked during written test from Microsoft. I am giving the question and the answer that I came up with. Thing is my answer although looks comprehensive (at least to me), I feel that the number of lines can be reduced. It was asked in C and I am a Java person but I managed to code it (my answer...

C++ Linked list behavior

I have some C code, where in there are two linked lists(say A and B) and A is inserted at a particular position into B and A still has elements. How do I simulate the same behavior effectively using the C++ STL? If I try splice, it makes the second one empty. Thanks, Gokul. ...

Which Data Structure? LinkedList or Any Other in Java?

I have specific requirements for the data structure to be used in my program in Java. It (Data Structure) should be able to hold large amounts of data (not fixed), my main operations would be to add at the end, and delete/read from the beginning (LinkedLists look good soo far). But occasionally, I need to delete from the middle also and ...

Yield Return In Java

I've created a linked list in java using generics, and now I want to be able to iterate over all the elements in the list. In C# I would use yield return inside the linked list while going over the list of elements contained in the list. How would I go about creating a java version of the above where I can iterate over all the items con...

help in displaying the sum of two matrixs (using linked lists)

hey there, Im having problems displaying my results in this program but the program compiles. Any idea as to what is going wrong?. The purpose of the program is to take two, 2 by 2 matrixes and add them to create the matrix called result. but when it comes to displaying the values in each matrix (A,B and result) it hangs. why does at the...

Linked List Implementation In Java and Garbage Collection

If I have a linked list structure, and I implement the clear() method as follows: public void clear() { firstNode = null; size = 0; } will it still get correctly garbage collected, or would I want to walk through each node, setting nextNode to null? None of the nodes can be directly referenced from outside the linked list, so...

Template class, static function compile error c++

I have the following function defined inside my linked list class. The declaration in the header file looks like this: template <typename T> class RingBuffer { ...//stuff static BLink * NewLink (const T&); // allocator }; BLink is a "link" class within the RingBuffer class. The following implementation code: template <typename ...

Different Types of Linked Lists!

What are the different types of Linked Lists which are commonly used? I know and have used the following: Singly Linked List Doubly Linked List Circular List What are the other kinds of lists that have been used by you or known to you? ...

C Linked List Memory Usage (Possible memory leak)

Hi, I'm having trouble with what should be a simple program. I've written a single linked list implementation in C using void* pointers. However, I have a problem, as there is a possible memory leak somewhere, however I checked the code using valgrind and it detected no such errors. But when all the memory is free'd there is still som...

Total size of a linked list in C

Alright... my Introduction to Data Structures from CS is so rusty I need to ask this here. I have a linked list whose structure is: struct Data_Struct { char *Name; char *Task; char *Pos; struct Data_Struct *Next; }; typedef struct Data_Struct MyData; Now, at some point in my application I filled the list with data. ...

C# : Anyone know how to fix this? : The type or namespace name 'T' could not be found

Im really having trouble fixing my code, was wondering if there was anyone out there who could help me. Basically im getting the following error: The type or namespace name 'T' could not be found (are you missing a using directive or an assembly reference?) The following are my classes: Program Class: using System; using System.Coll...

Make a local copy of data going into a linked-list

this one is not homework, it just the fact that i've been out of school for more than 20 years and I NEVER had to use linked lists for anything at all. So i'm out of my element here. anyway, I have struct Data_Struct { char *Name; char *Task; char *Pos; struct Data_Struct *Next; }; typedef struct Data_Struct MyData; Wh...

LinkList Pointer

I have a linklist A->B->C->D my head pointer is on A i want to delete node c with only one head pointer. i dont want any code just explanation. ...

C# - MCTS - Create a generic linked list class to create a chain of objects

Hi folks, please explain what this task is about? "create a generic linked list class that enables us to create a chain objects of different types." Do we need to create a class of type linkedlist and implement list interface? class LinkedList<T>:IList<T> { //implement interface methods here? } Please give example. TIA ...