FAQ Database Discussion Community


Solution to Finding Start of Loop in a Circular Singly Linked List

set,hashset,singly-linked-list
The common solution that I find to this problem is to use 2 pointers that advanced through the linked list at different intervals (i.e. have p1 traverse one node at a time and p2 traverse two nodes at a time) until p1 and p2 are equals. Example: Finding loop in...

Is there a mistake in this illustration?

java,data-structures,linked-list,singly-linked-list
In chapter 14.2, page 620, in "Big Java" (International 4th edition), by Cay Horstmann, it is shown how to implement a linked list. The add method of the listIterator looks like this: public void add(Object element) { if(position == null) { addFirst(element); position = first; } else { Node newNode...

understanding linked lists

java,linked-list,singly-linked-list,doubly-linked-list
I am having trouble understanding linked lists from my course. The biggest problem I seem to have is how the data is stored. I see the code mainly add(x) add a new node in the list but it does not seem to make sense. The code for add. boolean add(T...

Java Self-Programmed Singly-Linked-List in Linked-List

java,linked-list,singly-linked-list
At least for me, I have a tricky exercise to do for university. The task is to program a singly-linked-list with all kind of methods. So far so easy, but the challenge is to store these singly-linked-lists afterwards in a Linked-List. In the following you see my implementation of my...

Check for a value using LinkedList

c++,singly-linked-list
void List::IsinList(int resnum){ Node* temp = head; while (resnum != temp->_number && temp != NULL){ temp = temp->next; } if (resnum == temp->_number) cout << resnum << " is reserved for " << temp->_name << endl; if (temp == NULL){ cout << "Information not found" << endl; exit; }} Recently...

Unable to display nodes of the list properly starting from the tail to head

java,linked-list,singly-linked-list
My insert method explanation: I assigned the "next variable" of tail to hold the address of the old node. I assigned the tail with the new node inserted into the list. I tried to display the list starting from the tail and going through the list until it reached the...

Java Singly-Linked-List Recreation

java,singly-linked-list
So for an assignment I need to basically make a singly linked list, with 2 methods, add(x) This adds a new node to the end of the list, and a deleteMin() that removes from the end of the list At the bottom is the code I made. I keep on...

Spliting Singly Linked List

c++,linked-list,singly-linked-list
I'm trying to split a singly linked list into 2 singly linked list. l1 will get 30% members of l and l2 will get the next 30% of l. I don't know what wrong with my code, so please help me. Thanks. P/s: Sorry for my bad English. #include <iostream>...

Singly linked list - push_back

c,list,linked-list,singly-linked-list
I have to create method push_back which will add an item to the end of my list. But I have one constraint - I can't check if head is empty (if head is null) I don't have idea how I can do this. Here is my code: #include <stdio.h> #include...

Output( ) from a Set class with Singly Linked List Hash Table

java,set,hashtable,singly-linked-list
I have code that I have been working on going on 10 hours now, and for the life of me, I am unable to get the output( ) of my Set.java to work. Unfortunately I am not allowed to just import the Iterator or HashTable classes from java library. Any...

linked list built but not working properly

c,pointers,linked-list,singly-linked-list
I have numbers in a linked list which i am supposed to convert to char* and return . Here is is the function where the problem probably exists. char* int_str(struct Node** head,char* result) //head is pointer to singly linked list { struct Node* temp = *head; char* string1=""; char* str;...

What is the list that is being built by this code?

c,list,singly-linked-list
Can someone tell me what the exact list is that is being built by this program? (the program does not run, which is fine). Also, any lines of code that you can be pointed out to me that pertain to making the list would greatly be appreciated, I'm having trouble...

Linked List reversal in C not working

c,linked-list,singly-linked-list
I want to do some operations with linked list in C. I have wrote some functions for this like - Insert at beginning, Insert at tail, Delete from beginning etc. In my code I tried to implement reversal of linked list. But it is not working as expected. It always...

(2nd term C++)(Homework)Linked Lists Advice

c++,singly-linked-list
I am currently writing a program in C++ that uses linked lists. The problem is, I can't really seem to figure out how to use linked lists. I know (A little) how to use classes though. This is the LinkedList.h file given by the teacher (So I can't modify anything)...

Copy Constructor Error With a Template Linked List Class

c++,copy-constructor,singly-linked-list
I am doing an assignment on linked lists using a template class. In my main.cpp I should be able to create the list (which works) and create another list using either the assignment operator or the copy constructor. Here is my code: template <class T> LinkedList<T>::LinkedList(const LinkedList<T>& other) { Node<T>*...

What is the reason for this segmentation fault in this Linked List program?

c,segmentation-fault,singly-linked-list
This program always gives me a Segmentation Fault when I add the last node, what could be the possible reason. it only comes while adding the last node, I have commented the line in which I get the segmentation fault. I'm new to programming. #include<stdio.h> #include<stdlib.h> struct node{ int data;...

Singly linked list, why is the list empty (head == NULL)?

c++,list,c++11,data-structures,singly-linked-list
I created a singly linked list: #include <iostream> using namespace std; struct Node{ int data; Node *next; }; bool isEmpty(Node *head){ if (head == NULL){ return true; } else{ return false; } } void append(Node *head, Node *last, int data){ Node *newNode = new Node; newNode->data = data; newNode->next =...

Need Help Fixing Linked List Implementation + append method

python,linked-list,singly-linked-list
For practice and to prepare for programming interviews I've by doing problem sets from cracking the interview by Gayle McDowell. That being said I've been answering all the problems in both Python and Java. I'm working with linked list in python at the moment, since i've completed it all in...

How to insert array elements into a Singly-Linked-List?

java,singly-linked-list
I implemented a Singly Linked List (IntSLList) in Java. I debugged it and it also has adding, deleting and searching methods. I created an array(integer) and I want to add the array elements to the list. How can I add all the array elements to the list? public class IntSLLNode...

C++ Changing from singly linked list to doubly linked list

c++,linked-list,singly-linked-list,doubly-linked-list
I wrote this code using singly linked list. Now I want to change it to doubly linked list. I have tried few different things but everything messed up. There are few useless lines in my code, but it is basically a singly linked list. What is the proper way to...