linked-list

Why is clear an O(n) operation for linked list?

蓝咒 提交于 2019-12-11 06:46:31
问题 According to attachment 1, linked list's clear operation is O(n). I have a question about why is it so. Here is how we implemented the linked list in class(java) public class LinkedIntList { private ListNode front; ...... } And if I were to write a clear method for this linked list class, this is how I would write it public void clear() { front = null; } Given this implementation(think this is how most people would write this), this would be one operation that is independent of the size of

Windows singly linked list (_SINGLE_LIST_ENTRY)

末鹿安然 提交于 2019-12-11 06:12:43
问题 I'm just doing some debugging on a Windows 7 crash dump, and I've come across a singly-linked list that I'm not able to fully understand. Here's the output from WinDBG: dt _GENERAL_LOOKASIDE_POOL fffff80002a14800 -b .... 0x000 SingleListHead: _SINGLE_LIST_ENTRY +0x000 Next: 0x0000000000220001 .... From what I've been reading, it seems that each singly linked list begins with a list head, which contains a pointer to the first element in the list, or null if the list is empty. Microsoft state:

swap last two nodes of singly-linked list

陌路散爱 提交于 2019-12-11 05:36:33
问题 How can I swap the last two nodes of a linked list? I'm trying to use a helper node as I think it's needed to avoid 'losing' a node in the process... ... Node node3 = new Node("Hi", null) ; Node node4 = new Node("Hello", null) ; ... // swap node3 & node4 Node temp = node3.succ ; node3.succ = null ; // this should be the last node now, so i set its pointer to null node2.succ = temp ; // the second's node successor becomes what used to be the last node temp = node4 ; // not sure how to use temp

Creating a linked list without pointers but indices [duplicate]

若如初见. 提交于 2019-12-11 05:23:27
问题 This question already has an answer here : Is it possible to create a single linked list with indexes but without pointers? [duplicate] (1 answer) Closed 2 years ago . My teacher wants me to create something like linked list but using indices instead of pointers. So the Node contains int data and int index . Can you drop me a hint how would I do that? I know how to create it with pointers but how to do without them? He mentioned pool as a container though. 回答1: Your struct Node would be like

How a LinkedList Keeps Track of All Nodes - C#?

泪湿孤枕 提交于 2019-12-11 05:07:16
问题 I have been struggling trying to develop my own singly linked list, I cant understand how a node is inserted at the end of a Linked List? Here's the code: class LinkedList { private Node head; public void AddLast(int value) { if (head == null) { head = new Node(); head.value = value; head.next = null; } else { Node temp = new Node(); temp.value = value; Node current = head; while (current.next != null) { current = current.next; } current.next = temp; } } public void PrintAll() { Node current

Failing to remove the first node in a LinkedList, but succeed to remove other nodes

老子叫甜甜 提交于 2019-12-11 04:56:36
问题 I am practicing using Java's LinkedList . The purpose of the main method here is to remove the given index's node. The given node can be removed rightly, except the first node. If I changed removeLastKthNode(head, lastKth); into head = removeLastKthNode(head, lastKth) , it works. But I don't know why removeLastKthNode(head, lastKth) cannot remove the first node. Andreas gave me a link about this problem Is Java "pass-by-reference" or "pass-by-value"? However, problem here is that

Nested linked-list in c

强颜欢笑 提交于 2019-12-11 04:55:24
问题 My function AddItemToClient doesnt seem to work I'm not sure if its because of find function or because of AddItemToClient function but the output is strange. When I try to add item to another client than first one, it doesnt work but works propely only to first client but aswell adds to every existing client same item could somebody explain why? #include <stdlib.h> #include <time.h> #include <string.h> #include <stdio.h> struct date { int day; int month; int year; struct date* next; };

C - Unable to free memory allocated within a linked list structure

坚强是说给别人听的谎言 提交于 2019-12-11 04:48:31
问题 Consider the following code snippet struct node { char *name; int m1; struct node *next; }; struct node* head = 0; //start with NULL list void addRecord(const char *pName, int ms1) { struct node* newNode = (struct node*) malloc(sizeof(struct node)); // allocate node int nameLength = tStrlen(pName); newNode->name = (char *) malloc(nameLength); tStrcpy(newNode->name, pName); newNode->m1 = ms1; newNode->next = head; // link the old list off the new node head = newNode; } void clear(void) {

Nodes lost in linked list merge sort implementation in C

穿精又带淫゛_ 提交于 2019-12-11 04:27:01
问题 This implementation is used to order strings in ascending alphabetical order. I've included the functions responsible for the dividing of nodes. head is the head of the linked list. I believe the mergeSort function is working as intended to divide the list up. See the following ouput: Head: lady apple stone red queen fast: slow: stone front: lady apple stone back: red queen Head: lady apple stone fast: slow: apple front: lady apple back: stone Head: lady apple fast: slow: lady front: lady

implementing stack with linked list in C

情到浓时终转凉″ 提交于 2019-12-11 03:46:05
问题 I'm having trouble implementing a Stack using a linked list with struct. The program compiles fine but when I run it, it prints the first element but then reads the next node as a NULL. I think it might be an error with my passing of the stack to the push method but I am not sure and I have not been successful in fixing it so I'm asking for your help: #include <stdio.h> #include <stdlib.h> struct stackNode{ char data; struct stackNode *nextPtr; }; typedef struct stackNode StackNode; typedef