linked-list

Writing a merge method for lists

荒凉一梦 提交于 2019-12-06 15:24:11
I'm trying to write a method that merges a doubly linked list in an alternating fashion. So if we have two int lists (0,1,2,3) and (4,5,6), we'd just have one final list of (0,4,1,5,2,6,3). Each list has a head, a tail, a next, and a prev pointer. Its hurting my mind to try to figure out where to start or how this would work. I've tried to trace it on paper, but no progress. Can anyone guide me in the right direction? Whats a good way to 'picture' this or plan for it, as I dont even know where to start. Create a third, empty list (called the "result list"). Loop while there are still elements

asp classic how to trap errors when connecting to an oracle linked server

瘦欲@ 提交于 2019-12-06 15:02:06
I have a query in classic ASP like this: sql_test="select * from Openquery(it_test, 'select * from IT_DB.HOST') the problem is that I want to test the connection to the linked server before executing it and getting an error on the page. If the connection to the linked server doesn't work (ex: db down) I can execute a query on the local SQL server 2000 db avoiding getting an error on the page. I tend to use this code... 'GetDataSet error columns... const C_ERROR = "ERROR" 'Used when an error is generated - to be fed to the comsuming routine const C_NO_DATA = "NO_DATA" 'Used when no data is

Hashtable and list side by side?

谁说我不能喝 提交于 2019-12-06 14:33:55
问题 I need a data structure that is ordered but also gives fast random access and inserts and removes. Linkedlists are ordered and fast in inserts and removes but they give slow random access. Hashtables give fast random access but are not ordered. So, it seems to nice to use both of them together. In my current solution, my Hashtable includes iterators of the list and the List contains the actual items. Nice and effective. Okay, it requires double the memory but that's not an issue. I have heard

Creating Linked List, not passing back to Main

倾然丶 夕夏残阳落幕 提交于 2019-12-06 13:30:02
So I am creating a linked list in a separate function, and when I print out the linked list within the function, it seems everything is fine. However; when I go to main and try to access the linked list with printf I get a segmentation fault and am confused exactly why. void createLL(struct node* head, struct node* curr, char ch, int number){ //lowest digit is the head while (((scanf(" %c",&ch)) >= 0)){ curr = (struct node*)malloc(sizeof(struct node*)); //allocate space number = ch - '0' ; //convert char to number curr->data = number; curr->next = head; head = curr; } curr = head; /

Implementing linked list with iterator interface

烂漫一生 提交于 2019-12-06 13:27:10
Here's the problem. Write a function for merging multiple (sorted) linked lists into one sorted linked list. This function should access the elements through Iterator interface (do not access elements through the linked list directly). The arguments to the merge procedure are an array of Iterators and the size of the array. The return value should be another Iterator with an underlying List implementation. Steps: (1) Implement linked list with iterator interface. Define the Element in the list as below: typedef struct { int idno; char name[25]; float marks; } Element; (a) List createList(); (b

Linked list implementation in c without using double-pointer

怎甘沉沦 提交于 2019-12-06 13:17:14
I have implemented a simple linked list in C language, but can it be implemented without using double-pointer(**).I want to implement same program by using only single pointers. #include <stdio.h> #include <stdlib.h> struct node { int data; struct node *next; }; void push(struct node** head_ref, int new_data) { struct node* new_node = (struct node*) malloc(sizeof(struct node)); new_node->data = new_data; new_node->next = (*head_ref); (*head_ref) = new_node; } void append(struct node** head_ref, int new_data) { struct node* new_node = (struct node*) malloc(sizeof(struct node)); struct node

Linux Kernel Linked List

牧云@^-^@ 提交于 2019-12-06 13:12:42
问题 I'm trying to use the Linux Kernel Linked List implementation but I am unable to compile. I'm following these sources exactly with no results (http://www.roman10.net/linux-kernel-programminglinked-list/ and http://kernelnewbies.org/FAQ/LinkedLists) The list.h Kernel Macro for LIST_HEAD_INIT is as follows: #define LIST_HEAD_INIT(name) { &(name), &(name) } struct Node { int data; struct list_head list; }; struct Node mylinkedlist; LIST_HEAD_INIT(&mylinkedlist.list); void add(){ struct Node

Bubble Sort Manually a Linked List in Java

戏子无情 提交于 2019-12-06 12:01:40
问题 This is my first question here. I am trying to manually sort a linked list of integers in java and I can not figure out what is wrong with my code. Any suggestions? I don't get any error, however I still have my output unordered. I tried a few different ways, but nothing worked. I appreciate if anyone can help me with that. public class Node { int data; Node nextNode; public Node(int data) { this.data = data; this.nextNode = null; } public int getData() { return this.data; } } // Node class

Neo4j - How do you do parallel insertion into a linked list via Cypher over REST?

此生再无相见时 提交于 2019-12-06 10:42:53
I want to create a linked list using Cypher over REST. If I create the head of the list using the following query: MERGE (headNode:HEAD {list:"mylist"}) WITH headNode MERGE headNode-[:LINK]->(headNode) RETURN headNode And then do the insert using this query: MERGE (headNode:HEAD {list:"mylist"})-[old:LINK]->after DELETE old CREATE headNode-[:LINK]->(newNode:LINKNODE { number : {nodeNumber} })-[:LINK]->after Then everything is fine as long as I don't run multiple insert queries in parallel. But when I do I start to get consequences that are bad. I either get (depending on the timing) an error

Link list algorithm to find pairs adding up to 10

↘锁芯ラ 提交于 2019-12-06 09:25:08
Can you suggest an algorithm that find all pairs of nodes in a link list that add up to 10. I came up with the following. Algorithm: Compare each node, starting with the second node, with each node starting from the head node till the previous node (previous to the current node being compared) and report all such pairs. I think this algorithm should work however its certainly not the most efficient one having a complexity of O(n2). Can anyone hint at a solution which is more efficient (perhaps takes linear time). Additional or temporary nodes can be used by such a solution. If their range is