FAQ Database Discussion Community


How do I search through a Java Linked List

java,linked-list,inventory
I am working on my last assignment for my intro Java class. We are doing a Linked List (we built ourselves) Inventory program. I am having trouble with my findItem method. How would I search through my Linked List by Item number?? The way I am doing it works, but...

card game in c, shuffle linked list

c,linked-list,shuffle,realloc
I trying to shuffle a linked list in c. My idea was to move the list into an array of card then to shuffle the array and then to put it all back in the linked list. when I do build everything is ok but when id use the debugger...

Issues with reversing the linkedlist

java,algorithm,linked-list,nodes
I'm trying to learn about linked list and it has been little challenging for me. I'm trying to reverse the link list with recursive method. Here is my code: public class ListNode { Node head = null; int nodeCount= 0; int counter = 0; ListNode(){ head = null; } public...

Using the runner technique for linked list

algorithm,linked-list
So, I am facing a doubt here. I was reading the book Cracking the coding Interview. The following text is written over there. Suppose you had a linked list a1->a2....->an->b1->b2....bn, and you want to rearrange it into a1->b1->a2->b2->.....an->bn. You don't know the length of the linked list but all you...

What is the idiomatic way to write a linked list with a tail pointer?

linked-list,rust,reference-counting
As a learning project for Rust, I have a very simple (working, if incomplete) implementation of a singly linked list. The declaration of the structs looks like this: type NodePtr<T> = Option<Box<Node<T>>>; struct Node<T> { data: T, next: NodePtr<T>, } pub struct LinkedList<T> { head: NodePtr<T>, } Implementing size and...

reverse a linked list using recursion error

c,recursion,linked-list
I am understanding recursion and so I tried writing reverse a linked list program. I have written the below function but it says segmentation error (core dumped). void reverse(){ if (head -> next == NULL){ return; } reverse (head -> next); struct node *q = (struct node*) malloc (sizeof(struct node));...

how to create a linked-list in a hash-table with the specific index?

java,linked-list,hashtable,collision
public boolean isCollide(String key, String value){ int index = key.hashCode(); if (this.key_array[index]==null) return false; else return true; } public void addValue(String key, String value){ Hashtable hashtable = new Hashtable(key,value); int index = key.hashCode(); if (isCollide(key,value)) { hashtable.key_array[index]=key; hashtable.value_array[index]=value; } else{ LinkedList<String> linkedList = new LinkedList<>(); linkedList.add(value); //how to create a...

Reversing a linked list, why does head still point to original first element when it should not?

c++,c++11,linked-list
I am trying to reverse a linked list using the following program. However at the end head still mistakenly points to the first element of the original list. Where am I making the mistake? #include <iostream> struct node{ node(int val): value(val), next(nullptr) {} ~node(){ delete next; std::cout << "Deleting "...

I can't find the pointer error that's causing an intermittent crash. Can you?

c,pointers,linked-list
This works most of the time, but I get an occasional crash. There's a pointer problem somewhere but I can't see it yet. The code takes words out of a string, and builds a linked list of them. The words have to include adjacent punctuation, but no whitespace. For example,...

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...

Segmentation fault while implementing linked list in c

c,linked-list
I'm trying to create a simple linked list and insert a node at the end of the list. I'm getting a segmentation fault. #include <stdio.h> #include <stdlib.h> struct node{ int data; struct node *link; }; void create(struct node *head){ struct node* second = NULL; struct node* last = NULL; second...

How to delete doubly linked list data and return it?

c++,data-structures,linked-list,doubly-linked-list
template <class T> class Node { public: T data; Node<T>* prev; Node<T>* next; // default constructor (parameterized) template <class T> Node(T value) { data = value; prev = NULL; next = NULL; } }; template <class T> T CircularLinkedList<T>::RemoveAt(int p){ Node<T>* temp = head; if (head == NULL){ return 0;...

Removing a node from a LinkedList (C#)

c#,data-structures,linked-list,hashtable
I created a LinkedList class with a function delete to remove a certain node from the list if found, however it's not working: public class LinkedList { public Node head; <...> public void delete(string n) { Node x = search(n); //returns the node to delete or null if not found...

LinkedList Recursion

java,linked-list
public class LinkedList { Node head = null; int nodeCount= 0; int counter = 0; LinkedList() { head = null; } public Node reverseTest(Node L) { if(L == null || L.next ==null) { return L; } Node remainingNode = reverseTest(L.next); Node cur = remainingNode; while(cur.next !=null) { cur=cur.next; } L.next...

Memory address in linked list C++

c++,memory-management,linked-list
I have created an extremely simple linked list example in C++ to practice some interview questions. I am having one strange issue that I can't really seem to understand: while( cur ) { cout << "Index: " << indx << endl << "Current Add:\t" << &cur << endl << "Value:\t\t"...

Allocating new node in Linked List using C++ reference parameters

c++,pointers,linked-list
This code snippet is valid for creating new node at the begining. void push(node **head_ref,int n_data){ node *new_node= new(node); new_node->data=n_data; new_node->next=(*head_ref); *head_ref=new_node; } int main(){ node *head=NULL; push(&head,data); return 0; } This is invalid but why? What i am trying to do is create a reference parameter as mentioned in...

Linked list of different classes, how to access specific class functions with pointer?

c++,inheritance,linked-list
Ok so I have a linked list of Personnel. However, I can add to the list a Personnel, an Employee, a Faculty, or a Student, because the other 3 are child classes. Teacher directions: "Add a sub menu item and related functions (insert book) to allow a new book to...

Deep Cloning of Custom Linked List

java,linked-list,clone,deepclone
I am trying to implement clone method for deep clonning of custom linked list(of Rectangle objects). I am able to get the correct value when there is no element or only a single element in the list but not when there are more than one element in the list. I...

Python Doubly Linked List Node Removal

python,oop,data-structures,linked-list
I created a basic doubly linked list class in Python, and it has three methods: append, remove, and show. I fully understand the append method, and I fully understand the show method. However, I am mildly confused about the way my remove method works. These are my two classes -...

Struggling to transfer a doubly linked generic list to circular. (segfault)

c++,templates,linked-list
So I've got this non-circular doubly linked list sample and I find it rather hard to transfer it to a circular one. (segfaulting on the //added lines) Any advise would be nice. Thanks in advance. Also, should I use overloading to handle input of different types? How do I manipulate...

Keeping track of initial value of linked list

c,linked-list
Iterating through a linked list seems to be tricky for me sometimes (as I am learning). I keep doing stuff recursively, but I want to do this one iteratively. The next function adds the values from a list l to a list mx, if its value is greater than x:...

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...

Linked list deletion and duplication

c++,c,linked-list
In the code I copied newnode to the headnode and also to the temp node. But when I delete an instance of data, it seems to affect the other locations as well. When I freed newnode it also erases the content of head and temp .How is this happening? Though...

Error Queue implementation using Linked List

c++,data-structures,linked-list,queue
I am trying to impliment Queue using linked list but it goes stops unexpectidly. could not find why? #include <iostream> #include <string> using namespace std; Class Node for creating a node. class Node { public: int data; Node *next; }; Queue Class containing operations for Queue. class Queue{ private: Node*...

C++ Unable to Print Pointer Data of a Linked List

c++,linked-list,nodes
I'm dealing with a doubly Linked List. It's made up of classes and is centered around the current node (instead of a node in the beginning or end of the list). Now my print function will throw an error but only if I have traversed the list at all. My...

Why isn't the head node of my linked list being deleted?

java,linked-list
Okay, so i'm playing with linked list in Java. I'm trying to understand why my deleteNode method doesn't delete the head node. It works for other nodes. Here's the method Node deleteNode(Node head, int d){ Node n = head; if(n.data == d){ return head.next; } while(n.next != null){ if(n.next.data ==...

LRU cache with doubly linked list [closed]

java,algorithm,linked-list,lru
I Wanted to implement a memory cache. Found that LRU algorithm seems to be the good approach with a doubly link list. But I was unable to find any implementation guild related to this. Please advice how to approach for this.

How would I convert a const Class* to a Class*?

c++,linked-list,const
I'm trying to insert something into a linked list, but the compiler tells me that I can't convert from a const Student* to a Student*. Each node contains a Student *stud and a Node *next. This is what I have written so far of the function: void LinkedList::putAtTail(const Student &student){...

Unclear error in list implementation

c,linked-list,fscanf
I wrote a function to get input from text files, the "fileInput" function, and the content of my text file is like 1 2 4 5 2 4 5 6 the part of main function is like: case 7 head=fileInput(head);break; but for some reason, when I choose case 7 to...

How to check if a linked list is a palindrome or not in Java?

java,reference,linked-list,parameter-passing,value
I wrote a code to check if a singly linked list is a palindrome. And I made two steps: 1st. reverse the original linked list. 2nd. Check if the original and reversed linked list have the same element. public static Boolean isPalindrome(Node input){ Node reversed= reverse(input); while (input!=null){ if(input.item!=reversed.item) return...

Recursion - nth element from last in a linkedlist

c,recursion,linked-list
Can someone please explain the following function ? void printNthFromLast(struct node* head, int n) { static int i = 0; if(head == NULL) return; printNthFromLast(head->next, n); if(++i == n) printf("%d", head->data); } I just want to know how order of execution of statements occur in recursion i.e given recursive call...

Junk values in deletion of circular linked list

c,linked-list
The structure and function that deletes a node in a circular linked list is as follows: struct node { int data; struct node *next; }; struct node *head = NULL; void add(int n) { struct node *temp=NULL,*trav=head; temp = (struct node*)malloc(sizeof(struct node)); temp->data = n; if(head == NULL) { temp->next...

Copy Constructor is not working for linked list?

c++,c++11,linked-list,copy-constructor
The following is the class with the node structure, the linked list copy constructor, and my main file. It is printing the numbers in the first list and it only copies the first number (15) into the second list. It calls the destructors for both lists and the program closes...

c++ linked list creation linked list of linked list [closed]

c++,linked-list
the code send error in this line course["CS"].student=new Course*[1]; i want create linked list of courses contain linked list of students here is the code struct Student{ string name; int id; int grade; Student(string n, int i, int gd ){ name=n; id=i; grade=gd; } }; struct Course{ string C_Name; Student...

Linked List Seg Faults

c,linked-list
I'm getting a segmentation fault and I don't know where the problem is. #include "stdio.h" #include "stdlib.h" struct node { int data; struct node *next; }; struct node *head = NULL; struct node * curr; struct node * newNode; void createList(){ int data,n , i ; scanf("%d",&n); for (i =...

C - LinkedList Sorting Infinite Loop

c,sorting,linked-list
I am creating a program that will read a word from a text file in main.c, and send it over to list.c file to create a new node to store that word. The node will also store three ints: first (number of times this word appears in txt file 1),...

Changing nodes in linked list

c,list,linked-list
This is somewhat mind-boggling i will try to explain my doubt. Check this function for example: void snoc(Lint *l, int val){ Lint i, new; new = (Lint) malloc(sizeof(Nodo)); new->value = val; new->next = NULL; i=(*l); while(i->next!=NULL){ i=i->next; } i->next = new; } I understand the concept behind and i have...

Deleting multiple nodes from simple linked list on C

c,list,linked-list,nodes,erase
I want to delete all nodes that have the same idteam as key, but it will crash... I know it should also free() the memory, but anyway I thought this should work :S //defining the struct struct players { int idplayer; int idteam; struct players *next; }; struct players *first,...

How can I restart a double linked list?

c,linked-list
I'm coding a program to multiply two polynomials. I need some advice as to how I can restart the double linked list in the nested while loop in the polyProduct function. I mean, at this point I need to go back to the first position of the list. This is...

using a list iterator to iterate through Linked List Java

java,linked-list,iterator
For this program we are to create a LinkedList of type Song. Song contains two instance variables, title and artist. The user is prompted to enter a command (either add, remove, print, or quit). I am having problems with the remove method. We are not allowed to use a regular...

Copying a linked list onto another linked list - iteratively - C - understanding the returned list

c,algorithm,linked-list
Trying my hand at linked list problems, and for today I'm trying "given a linked list, copy it to another linked list" For doing this iteratively, The logic would be - Use three pointers - current, newList, newTail. current to keep track of the current node in the given, original...

find element in linked list

algorithm,linked-list,computer-science
There is a data structure providing iterators with the following interface: struct iterator { T value(); void next(); bool isValid(); } How would you design an algorithm which at the end of the loop returns some value from the list with equal probability for each element? The list can be...

LinkedList iterator remove

java,linked-list,delete,iterator
I have a question on linkedlist iterator If I'm using next , previous and remove methods for example : name.add("Alvin") name.add("Keven") name.add("Jack") ListIterator<String> iterator = name.listIteraot(); //|AKJ iterator.next(); // A|KJ iterator.next(); // AK|J iterator.add("Nina") // AKN|J iterator.next(); // AKNJ| iterator.remove(); // AKN| In the next and then remove method we...

Linked list of pointers C++

c++,linked-list
I have a list but now I have to link it. Here is my program ( I deleted code inside functions to make my program more easy to read ). #include <iostream> using namespace std; struct Student { char ime[16]; char priimek[16]; char vpisna[10]; char ocenaRV[10]; char ocenaDN[10]; char ocenaKV[10];...

Big-O for 2 dimensional array and Linked list

c++,c,arrays,linked-list,big-o
I've made a game by using 9 linked Lists and the other 1 linked lists gets all the address of the other 9 linked lists. Therefore, something like a 2 dimensional array by using linked list. I'm trying to calculate Big-O that my data structure fits and is better than...

Array of pointers to linked list

c,arrays,pointers,linked-list
I need to know if i want to make an array that every element of the array is a pointer to a linked list and pass the array to a function, the function is void because I need to change the array typedef struct n{ char *S; int num; }list;...

Array of List of class Association Generic

java,arrays,list,generics,linked-list
I saw all the past Questions in StackOverflow, I don't find an appropriate answer of my Question. I want to create a Array of List of class Association, but after execution, I have an Exception like that in the line : private static final int SIZE=99999; private List<Association <K,V>> []...

Adding to the head in a doubly linked list

c,linked-list
I have the following: typedef struct value value; struct value{ value* prev; value* next; int value; }; ... //ent = entry if(entry_head == NULL) { entry_head = ent; entry_tail = ent; entry_tail->prev = NULL; } else { // add to top entry_head = ent entry_tail = entry_tail->next; } When I...

Linked List Operations in C Read Proof

c,data-structures,linked-list
I am trying to write up all the linked list basic operations (push, pop, add_at_end, pop_from_end, add_at_index, pop_from_index). This is not a school assignment, even though it may look like one. I have written the code. I have tested it myself quite a bit, although I am no C guru....

Inserting an element into an already sorted linked list

java,linked-list
I am creating a function that inserts an element into a linked list in the correct order without resorting the list. Here's the code I have: public void insert(E e) { if (e == null) throw new NullPointerException(); if (head == null) { head = new Node(e, null); count++; }...

Binary to Int Linked Lists In Java

java,linked-list
I have created a Linked List that is to store a binary number in String and covert it to single bits and store in a Link each. My problem is that I have done all of that and I am now trying to create a method to take the bits...

How to properly unit-test a linked list (using Python)?

python,unit-testing,linked-list
I'm new to TDD. I've created all the main functions (insert, search, remove etc.). This is my insert_beginning() function: def insert_beginning(self, node): ''' Inserts a Node to the beginning of the list. ''' node.set_next(self.head) self.head = node My question is, how do I properly unit-test this function? The only way...

Return type of list front (C++)

c++,function,reference,linked-list,return-type
So I want to use a list for a part of my program. I'm trying to get acquainted to the library list, so I wrote a quick little program to help myself understand what's going on. It all works properly, but there's one thing I don't understand. According to this:...

Are Lisp lists always implemented as linked lists under the hood?

linked-list,lisp,cpu-cache
Are Lisp lists always implemented as linked lists under the hood? Is this a problem as far as processor caching goes? If so, are there solutions that use more contiguous structures which help caching?...

Python Linked list minimum value

python,list,python-3.x,linked-list
I am trying to find the minimum value in the list without having to use the min function and just by comparing the first and the next element through the list. This is my attempt: def min(self): node = self.head #1st element Min = 0 #node.next_node is the next element...

linked list change when i change the array of character

c,string,pointers,struct,linked-list
The problem is when the second time i put a any word the q->ch in the if statement change to the new word .. I want q become the pointer of the start of the linked list while(true){ tmp=(list*)malloc(sizeof(list)); printf("\n put any word:"); scanf("%s",name); printf("\n"); tmp->ch=name; if (i==0) { q=p=tmp;...

C - Singly linked list - passing a pointer by value vs by reference

c,pointers,linked-list
typedef struct node { int data; struct node *next; } NODE; NODE* add_head(NODE **phead, int data) { NODE *new = (NODE *)malloc(sizeof(NODE)); new->data = data; new->next = *phead; *phead = new; return new; } NODE* add_tail(NODE **phead, int data) { NODE *p, *new = (NODE *)malloc(sizeof(NODE)); new->data = data; new->next...

How do I implement generics in a linked List?

java,generics,linked-list
I have been trying to create a linked list that uses generics to return a data type of the user's choosing. The problem is that my method public E get(int sub) is not recognizing my return cursor.contents as a type E generic. public E get(int sub) { Node cursor =...

Why is my linked list only printing last entry?

c,file,linked-list
Im trying to read specific lines from a file and add it to a linked list and then print it out. Code bellow : #include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct list { int uid; char* uname; struct list* next; }node; void push(node ** head, int uid ,char* uname)...

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...

How to conditionally remove an element from a list using an iterator?

c++,linked-list,listiterator
Problem: I am writing a simple file manager application. In this program I have a "Directory" class: class Directory { public: Directory(string address, string directoryname) { this->path = address; this->name = directoryname; } string GetFullPath(){ return path == "/" ? path + name : path + "/" + name; }...

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>...

Find middle element of a double linked list in constant time complexity

linked-list
I am trying to find the middle element of a double linked list in constant time complexity . I came across the following http://www.geeksforgeeks.org/design-a-stack-with-find-middle-operation/ solution. But I don't understand how to use the middle pointer. Can anyone please help me understand this or give me a better solution .

Reversing a Linked Node Python

python,linked-list
I'm having trouble trying to reverse a linked node in Python. I've been looking at several solutions online, but they've hurt my head as I've tried mapping them on paper. How exactly does one reverse a linked node?...

Linked List issue insert from middle C++

c++,linked-list
I am new to linked lists, and now I face a problem on how to add the node into the middle of a list. Example like if I got a name list show below and when I add data one by one just like below sequence: 1.andrew 2.eric 3.madness 4.gerik...

Why Linkedlist in hashmap?Why not other implementation of List?

java,arrays,linked-list,hashmap
As HashMap uses LinkedList when two different keys produces a same hashCode.But I was wondering what makes LinkedList a better candidate here over other implementation of List.Why not ArrayList because ArrayList uses Array internally and arrays have a faster iteration compared to a LinkedList.

Bubble sort double linked list

c,sorting,linked-list,bubble-sort
Hello everyone I'm trying to sort my double linked list in C using bubble sort algorithm. Here is my code: struct node { unsigned char key; unsigned char num; struct node *left; struct node *right; }; Here is my sort funcion: void sort(int count, struct node *t_node) { struct node...

Build Alternative Data Structures with MultiValue Arrays

dictionary,data-structures,linked-list,multivalue,pick
I have been programming with PICK for a few months now, and am still adjusting to thinking of programming solutions that solely use multi-value arrays. PICK doesn't natively offer any other data structures for either database or in-memory operations * (ignoring dimensioned arrays for the sake of argument since they...

postfix calculator having trouble with segfaults

c,linked-list,segmentation-fault,postfix-notation
i'm trying to create a postfix calculator using linked-list. when i compile, it doesn't show any errors but when it's executed it would show Segmentation Fault. i don't know how to deal with this, please help. here's my code: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> typedef struct node...

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...

Dynamically allocated doubly linked circular list class instances segfault C++

c++11,linked-list,segmentation-fault,dynamic-programming
Using this template class works perfectly fine when main operates with constructed variables of type dlring, yet my goal is to allow dynamic allocation, so I can handle a non-predefined number of doubly linked circular lists to allow usage of such functions as: Splitting a list into two by either...

Bubble sort on linked list

c,sorting,data-structures,struct,linked-list
I'm trying to write an implementation of bubble sort to sort a linked list, but at the moment it's causing my program to crash. Here's how the structures are defined: typedef struct shopping_cart cart; struct shopping_cart{ char *item_name; int quantity; cart *next; }; And here's my code: void sort(cart *head){...

Removing Cycle in Linked List

algorithm,pointers,linked-list
Question: To find starting node of loop if cycle exists in linked list Approach: (1)Using Hare-Tortoise algorithm, find if cycle exists(No issues with this step) (2)Let P be the node where hare and tortoise meets.Let H be head pointer on linked list.Traverse one node at a time from H and...

Mimic a LinkedList with a simple float[]

java,android,arrays,linked-list
I have to draw on a SurfaceView the trails of some object moving around. The trail of an object is implemented as a LinkedList of points (a point is a pair of float coordinates on the SurfaceView). The LinkedList is motivated by a behaviour like that public class Trail extends...

threads safe linked list fine grained in C

c,multithreading,linked-list
I'm implementing a linked list with fine grained locking, meaning a lock in every node. When I'm adding a new node, I want to pass only 2 arguments: key and value. How can I make sure each node has a different lock? The lock is implemented by pthread_mutex_t. This is...

Recursion of Linked List

java,recursion,nullpointerexception,linked-list
When given an array of integers, I'm trying to change each element with the product of the integers before it. For example, int[] array = {2,2,3,4}; is now: {2, 4, 12, 48}; I added each element to a LinkedList, and I'm trying to do this recursively. This is what I...

<< Definition using inheritance and templates [duplicate]

c++,templates,visual-studio-2012,linked-list
This question already has an answer here: What is an undefined reference/unresolved external symbol error and how do I fix it? 18 answers I am trying to implement a Linked List in C++ using templates. Unfortunately I am getting an unresolved external error when I try to use a...

Deletion in Link List showing “0”

c++,linked-list
I cannot figure it out why am getting a 0 when trying to delete the first element of the list? I have inserted 3 elements (7,8,9),when am deleting 8 or 9 its working fine for me ,but when am trying to delete 7(.i.e the first element) irrespective of the no...

Linked list data edit deletes entire list

c++,linked-list
My class is asking for a program that is capable of inserting projects (this task is working) and giving an evaluation back to them. The problem is when I try to give an evaluation, the program just deletes the whole list, and I don’t know why. Here is the evaluation...

Adding a Object to End of a Linked List in One Class

java,class,methods,linked-list
I am a bit new to LinkedList and I want to practice by making methods in ExampleLinkedList class. There is a list in test3. When I call test3 I get Goodbye Thanks Hello. What I want is to add "AddedItem" in the end of the list to get AddedItem Goodbye...

Getting “symbols not found” errors implementing a Stack as Linked List using templates

c++,templates,linked-list,stack
I'm trying to create a stack using a linked list. I've already got it working using integers, but now I want to implement Templates to it. There are no errors detected before compile, but after running I get these errors: *Undefined symbols for architecture x86_84: "Stack::printStack()", referenced from: _main in...

Error : Expected expression before 'DATA /* : typedef struct DATA DATA */

c,struct,compiler-errors,linked-list,typedef
I don't know what's the problem here my code. I read some questions of others that had the same problem , but I didn't found an answer. When I try to compile I get this errors : ||In function 'main':| |35|error: expected expression before 'DATA'| ||In function 'lecture_data':| |59|error: expected...

How would one replace a vector with a linked list c++

c++,list,vector,stl,linked-list
I have a code with a template class and a few data members, the code for vector looks like this std::vector<Check> ck(100); how would one go about making this into a linked list?...

Difference between ways of sorting linked lists c++

c++,sorting,linked-list
I was thinking about ways of sorting a linked list and I came up with two different ways (using BubbleSort, because I'm relatively new at programming and it is the simplest algorithm for me). Example struct: struct node { int value; node *next; }; The two different methods: Rearranging the...

Reversing a linked list recursively in C

c,recursion,linked-list
I was trying to write a program to recursively reverse a singly linked list. My logic was to use two pointers prev and head. These two pointers are used to link two nodes in a linked list at a time. But I am not able to determine the base case...

Efficiently adding element to the top of the list

java,list,arraylist,enums,linked-list
I have an ENUM like this from which I always get what is my localFruit which can be either APPLE or ORANGE or BANANA. public enum Fruits { // it can have more elements here APPLE, ORANGE, BANANA; // some code } So let's say if APPLE is my localFruit,...

Flatten a Linked List in Java

java,data-structures,linked-list
I am trying to flatten a multi level linked list. Given a linked list where every node represents a linked list and contains two pointers of its type: (i) Pointer to next node in the main list (we call it ‘right’ pointer in below code) (ii) Pointer to a linked...

Classic List of object in C++ using pointers [closed]

c++,pointers,linked-list
I'd like to make one directional list of objects in C++. I've got 3 classes: BasicMiachine,Desktop,Laptop. Two last classses extends BasicMachine. What I want to do is make a list of object (Desktop,Laptop) using only one list. In Basic Class which is abstract class (because I have declare one method...

Number Format Exception and Regex Inquiry

java,regex,arraylist,javafx,linked-list
I'm trying to take in a mathematical expression from the user, but I keep getting a Number Format Exception here: Exception in thread "JavaFX Application Thread" java.lang.NumberFormatException: For input string: "(13-1)*(12-10)" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.lang.Integer.parseInt(Integer.java:569) at java.lang.Integer.valueOf(Integer.java:766) at Main.lambda$start$2(Main.java:134) at Main$$Lambda$73/16094097.handle(Unknown Source) Here is my Event-Handler that I am using...

Add item to LinkedList located in another class

java,class,linked-list
My linked list in Client class: private LinkedList<Client> clients = new LinkedList<Client>(); These are methods located in Client class: public LinkedList<Client> getCList() { return clients; } public void addClientList( Client newclient) { clients.add(newclient); } In another class called UInterface I am trying to add some elements to my list: Client...

Sending LinkedList of Objects through ObjectInputStream throws exceptions 'NotSerializableException' and 'StreamCorruptedException' [duplicate]

java,sockets,exception,linked-list,network-programming
This question already has an answer here: StreamCorruptedException: invalid type code: AC 2 answers I'am writing a simple copy of 'Space Invaders'. I want to add network feature, and atm I have problem with Writing/Reading data. So I have a LinkedList of (objects)Aliens and I want to send this...

change element position in linkedList

java,linked-list
I know we can change element position by creating new node and play with node references. How can i change element position without creating or deleting node, only by play with node references? many thanks! public class LinkedList<E extends Comparable<E>> implements Iterable<E> { private Node head; // reference to the...

How to implement a linked-list with multiple nodes in C?

c,pointers,data-structures,linked-list
I am making linked list(s) based on the user input as the following: How Many employees? 4 Now, each one would have firstname lastname rate and zipcode, with a linked list I am trying to take these inputs and doing a for loop based on the number of records, but...

Ascending order in linked list in c

c,pointers,struct,linked-list
I am trying to do ascending order in linked list through change of links and addresses rather than value struct node { char name[30]; int percent; struct node *link; }; int main { clrscr(); randomize(); struct node *st; st=NULL; for(int i=0;i<7;i++) append(&st,random(101)); //Assigning random values to structure node->percent display(st); AscMarks(&st);...

Floyd algorithm - Cycle Detection - not terminating for the example

c++,algorithm,linked-list,cycle,floyd-cycle-finding
Can someone please explain Floyd algorithm with this example. It is not terminating for me and is the algorithm implemented complete ?. Is something wrong with my code? Code is as follows: Node* FindLoopBegin(Node *head){ Node *slowptr = head,*fastptr = head; bool LoopExists = false; while(slowptr && fastptr){ fastptr...

Initializing a pointer to a struct with malloc [duplicate]

c,pointers,linked-list
This question already has an answer here: How do I modify a pointer that has been passed into a function in C? 5 answers This might be a question with a very simple solution but I can't get my head around it... I'm trying to implement linked list for...

Basic Linked List in C

c,linked-list
I'm writing a basic linked list program in C and having a bit of trouble with deletion. Here's what I have: #include <stdio.h> struct node * delete(struct node * head, struct node * toDelete); void print(struct node * head); struct node { int value; struct node *next; }; int main(int...

Why does ListIterator provide an index for elements in a LinkedList?

java,linked-list
Unlike an ArrayList, a LinkedList can not access an element at a particular point using an index. If this is the case, then what is the point of the ListIterator providing functionality that returns the index of a particular point in a LinkedList? Why would I ever need to know...

Return the (2n/3) element in a linked list while looping once on the list

java,oop,methods,linked-list,nodes
I'm working on a linked-list program, which allows me to loop over the list only once, and I can't copy the elements of the list to another data structure. Suppose that the list is not empty (has at least one node) and the next of the last node is null....

Insertion at index of LinkedList

java,linked-list
Hi I have this method to insert an element at any index of the LinkedList, however, the new element is not showing in the output, what did i miss thanks! I have showed partial code below, any help is greatly appreciated! public class LinkedList<E extends Comparable<E>> implements Iterable<E> { //...