linked-list

Huge performance difference between using linkedlist and array for constructing a graph with adjacency list

心已入冬 提交于 2021-01-29 11:28:50
问题 i'm working on an assignment about huge graphs and i have to construct the main graph (as adjacency list) from reading a .txt file which nearly has 5 billion lines.Actually, graph consists of 870k vertices. Whatever, i realized that there is a huge time difference ( more than 2 hours) between my first and second implementation. I'm curious about why there is such an unnegligible difference between these two implementations. Here you can see the main simple code about reading the txt file and

Pointer in Ruby

有些话、适合烂在心里 提交于 2021-01-29 09:20:28
问题 I just solved some tasks about linked lists using Ruby. It was very interesting, but it requires a couple of new lines. Because if I pass head in some function, and change the head of the list, I have to return new head from method and reassign it to the variable. Because if I have a variable and I pass it to method, reassign a inside, outside a dose not changes: it "dose not changes if reassign variable in method" do a = [1,2] def reasign array array = [1] array end assert_equal [1], reasign

JDK8 performance of ArrayList compared to LinkedList

六眼飞鱼酱① 提交于 2021-01-29 03:30:32
问题 I am starting to see more and more benchmarks that demonstrate ArrayList crushing LinkedList in terms of performance for 'large' inserts example below: Gluelist Adding(1M) Elements (5 Tests Avg.) LinkedList: 174.8 milliseconds ArrayList: 76.4 milliseconds GlueList: 39.2 milliseconds Adding(10M) Elements (5 Tests Avg.) LinkedList: 8975.6 milliseconds ArrayList: 4118.2 milliseconds GlueList: 3320.1 milliseconds I ran similar tests on a RHEL 7.2 with JDK8.latest and saw similar results. I am

Delete Node - Linked List - C

泪湿孤枕 提交于 2021-01-29 02:20:24
问题 I am trying to delete a node from a linked list but I am still new to the concept of double pointers so I tried using a global variable to hold the head pointer instead. However, I get the wrong results when I try to print my list after deleting the middle node. I saw this question deleting a node in the middle of a linked list and I don't know how is my delete node function different from the answer. Here is my code: #include <stdio.h> #include <stdlib.h> typedef unsigned char u8; typedef

Pop Function In Linked List Stack Results in Segmentation Fault- C

走远了吗. 提交于 2021-01-28 20:03:09
问题 I'm creating a stack using a linked list in C. The code is as follows: struct node{ int xposition; int yposition; struct node* next; }; void pushToTop(struct node** hd, int x, int y){ struct node* curr= *hd; struct node* prev=NULL; while(curr!=NULL){ prev=curr; curr= curr->next; } struct node* ptr= (struct node*)malloc(sizeof(struct node)); ptr->xposition=x; ptr->yposition=y; ptr->next=curr; if(prev==NULL){ *hd= ptr;} else{ prev->next=ptr; } } void popFromTop(struct node** hd ){ struct node*

Segregate even and odd nodes in a Linked List in C++

半世苍凉 提交于 2021-01-28 19:28:42
问题 So, I am self teaching Data Structure and Algorithm. While solving some problems I came across following problem where I have to segregate odd and even nodes of linked list. http://www.geeksforgeeks.org/segregate-even-and-odd-elements-in-a-linked-list/ Following is the problem statement: Given a Linked List of integers, write a function to modify the linked list such that all even numbers appear before all the odd numbers in the modified linked list. Also, keep the order of even and odd

Segregate even and odd nodes in a Linked List in C++

你离开我真会死。 提交于 2021-01-28 19:19:53
问题 So, I am self teaching Data Structure and Algorithm. While solving some problems I came across following problem where I have to segregate odd and even nodes of linked list. http://www.geeksforgeeks.org/segregate-even-and-odd-elements-in-a-linked-list/ Following is the problem statement: Given a Linked List of integers, write a function to modify the linked list such that all even numbers appear before all the odd numbers in the modified linked list. Also, keep the order of even and odd

Deleting node inside of linked list

南笙酒味 提交于 2021-01-28 13:46:23
问题 I'm stuck on this particular function that frees all even nodes from the linked list. I've figured out how to free all the nodes from a linked list but I cannot figure this out. The code i'm posting is very wrong. What I don't understand is how to use a node *temp variable and link it to the head->next node, as the head is what is being freed (because it is even). Also, at the end of the while loop, I know that I need to increment to the next node in the list, but I seem to be doing that

Deleting node inside of linked list

和自甴很熟 提交于 2021-01-28 13:46:08
问题 I'm stuck on this particular function that frees all even nodes from the linked list. I've figured out how to free all the nodes from a linked list but I cannot figure this out. The code i'm posting is very wrong. What I don't understand is how to use a node *temp variable and link it to the head->next node, as the head is what is being freed (because it is even). Also, at the end of the while loop, I know that I need to increment to the next node in the list, but I seem to be doing that

Using void pointer to simulate a generic linkedlist in C

ぃ、小莉子 提交于 2021-01-28 13:04:09
问题 I'm new to C, and I think there may be an issue with pointers here. Any help would be appreciated! I have a linkedlist struct that looks like this: ll.h: #ifndef LLTEST_LL_H #define LLTEST_LL_H #include <stdlib.h> typedef struct _listNode { void *data; struct _listNode *next; } listNode; typedef struct { int logicalLength; int elementSize; listNode *head; listNode *tail; } linkedlist; typedef struct table { const char* name; size_t col_count; size_t length; } table; typedef struct db { const