linked-list

Linked list vs Array in Javascript

删除回忆录丶 提交于 2019-12-10 14:40:07
问题 So I was playing around with the linked list in JS and came up with the following question: Lets say, that we have an array and a linked list both with 5000 elements. We want to insert new element at index 10. The array way is pretty simple. We insert the new element at the given index and move the rest of the elements one index forward. So I tried doing this with linked list and end it up with the following: Getting the implementation of linked list from Nicholas Zakas and adding additional

Total size of a linked list in C

倾然丶 夕夏残阳落幕 提交于 2019-12-10 13:55:06
问题 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. The question is, how do I get the total size of the data stored in there? How many chars are there? Something like sizeof(MyData); That will return the size of the info stored in

Correct Way to Override Iterables<Obj> in Java

女生的网名这么多〃 提交于 2019-12-10 12:31:21
问题 this is a code i have written for implementing linked list, private class DequeIterator<Item> implements Iterable<Item> { private Node pElement; DequeIterator() { pElement = first; } public boolean hasNext() { return pElement != null; } public Item next() { if (!this.hasNext()) { throw new NoSuchElementException(); } Item ret = pElement.it; pElement = pElement.next; return ret; } public void remove() { throw new UnsupportedOperationException(); } } I dont know what is going wrong i am getting

deleting a node in the middle of a linked list

给你一囗甜甜゛ 提交于 2019-12-10 12:17:45
问题 I have written a piece of code that uses linked lists. I get the user to enter a couple of numbers and then ask the user to enter the index of the digit he wishes to delete. I did some research and found out that i need to check whether the next node is the one I want to delete, then have 2 temp pointers point to the current node and the next node(which is the one i want to delete), then assign the next node of the first temp pointer to the next node of the second temp pointer then finally

How to write a linked list object to a file

此生再无相见时 提交于 2019-12-10 12:17:42
问题 void writeFile(){ Employer *temp = head; while (temp != NULL) { temp->tryWrite();//Employee's display method called here temp = temp->getNext(); } } void main(){ EmployerList em; em.AddNode("des@yahoo.com", "LIME", "Manager", "ming", "ding", "Newston", "43", "873"); em.AddNode("sw@gmail.com", "NOKIA", "CEO", "rew", "nbv", "Europe", "0411-789-6548", "985-257-1111"); //em.writeFile(); } I am trying to write the linked list to the file as an object instead of singularly like i have in the

Converting a Single Linked List to a Double Linked List

拜拜、爱过 提交于 2019-12-10 12:15:47
问题 I have here a single linked list for a program that makes a collage. This runs perfectly but I was wondering how to make it a double linked list. I really have no idea what a double linked is though or how to create one. Any help would be appreciated... There are 3 classes. class LinearCollage { private Picture myArray[]; private class Node { Picture data; Node pNext; }; private Node pFirst; private Node pLast; private int nPictures; private Picture clipboard; public LinearCollage() { pFirst

a linked list of linked lists in C

自作多情 提交于 2019-12-10 12:13:37
问题 I am making a project and was wondering if I could create a linked list of linked lists. I want to create a new type person in C in which, every person can have kids . kids are a list of person s and also every person has parents who are also person s.So I am thinking of doing that using structs and linked lists. #include <stdio.h> struct person { unsigned int id; //identity,unique for every person char* name; struct person **father; struct person **mother; struct kids **kids; } struct kids {

Expression Must have Class Type?

老子叫甜甜 提交于 2019-12-10 11:54:07
问题 So I've been playing around with Nodes and keep running into this error when I try to test it. If I use Parentheses I get this Error on list. - "Expression must have class type!" If I don't use Parentheses I get this Error on list , insert and display - "this is inaccessible." This happens when Declaring my LList in Main(). What's going on and why is this? My Driver #include "LList.h" #include <iostream> using namespace std; int main() { LList<int> list; bool test = list.insert(5); list

Linked list is empty after fetching data from Firebase realtime database

假装没事ソ 提交于 2019-12-10 11:49:30
问题 I fetch these department names (CSE, EEE) from firebase to a linked list and set that linked list as items of my drop down . When I click the drop down it shows the items but when I select an item it does not appears as selected item on the drop down bar. If I use array then the drop down works fine. But the problem is when I try to convert the linked list into an array using String[] arr = linkedlist.toArray(new String[linkedlist.size()] it shows that the linked list is empty. Normal drop

Algorithm to Find the pointer to the Node M Steps to Tail in a Singly Linked List

半世苍凉 提交于 2019-12-10 11:39:18
问题 Suppose there is a singly linked list whose length is unknown. We want to find the node with M steps to the tail. For example, the singly list is like this: (A)->(B)->(C)->(X)->(Y) and M = 2. Then the output should be pointer to (C). When confronting this quiz, my first reaction is to traverse the singly linked list to get the length N. Then traverse the singly the second time, but only forward N-M-1 steps. The time complexity is O(n) and space complexity is O(1). Then, I'm challenged to find