singly-linked-list

How does reference to pointer exactly work in C++, and when do we need them (in the case of linked list)

不问归期 提交于 2020-01-30 11:00:07
问题 I know that pointers hold the address of a variable. And references point to the same address in the symbol table (that is, the same address of the variable, that they are assigned to). My question is, how do reference to pointers exactly work. And when do we need them, as opposed to using pointer alone (and not using reference to pointer). It will be helpful if you could explain me the use of reference to pointer, with respect to a singly linked list. I have the following code that deletes

Linked list in C , Can't insert and display node

倖福魔咒の 提交于 2020-01-25 04:30:29
问题 I tried to implement the linked list but couldn't make out what is actually going wrong that it isn't showing the expected result? I tried to trace the control flow of the program by putting in random printfs at suspicious places... I tried to trace the control and realized that after inserting the first node the changes are not getting reflected in the original linked list; after getting back to main() the linked list is empty again! #include<stdio.h> #include<stdlib.h> struct node { int

sorting linked list simplest way

我的梦境 提交于 2020-01-14 06:08:28
问题 I am trying to code very basic sorting method for linked lists. I am getting unhandled exception. What is the mistake i am making? Here is my code:- struct LinkedNode// structure for linked list { int data; struct LinkedNode *next; }*start = NULL; following function creates a linked list void CreateLinkedList() { LinkedNode *newNode, *current; printf("enter 5 numbers to create linked list\n"); for(int i=0; i<5; i++) { newNode = (struct LinkedNode *)malloc(sizeof(LinkedNode)); scanf("%d",

sorting linked list simplest way

两盒软妹~` 提交于 2020-01-14 06:07:47
问题 I am trying to code very basic sorting method for linked lists. I am getting unhandled exception. What is the mistake i am making? Here is my code:- struct LinkedNode// structure for linked list { int data; struct LinkedNode *next; }*start = NULL; following function creates a linked list void CreateLinkedList() { LinkedNode *newNode, *current; printf("enter 5 numbers to create linked list\n"); for(int i=0; i<5; i++) { newNode = (struct LinkedNode *)malloc(sizeof(LinkedNode)); scanf("%d",

What are the space complexities of inits and tails?

大城市里の小女人 提交于 2020-01-11 09:23:09
问题 TL; DR After reading the passage about persistence in Okasaki's Purely Functional Data Structures and going over his illustrative examples about singly linked lists (which is how Haskell's lists are implemented), I was left wondering about the space complexities of Data.List 's inits and tails ... It seems to me that the space complexity of tails is linear in the length of its argument, and the space complexity of inits is quadratic in the length of its argument, but a simple benchmark

casting issue with linked list item

别等时光非礼了梦想. 提交于 2020-01-03 04:54:22
问题 This is my PER_IO_CONTEXT structure (i stored them in singly linked list): typedef struct _PER_IO_CONTEXT { SLIST_ENTRY ItemEntry; WSAOVERLAPPED Overlapped; WSABUF wsabuf; /* some other data*/ } PER_IO_CONTEXT, *PPER_IO_CONTEXT; and below is WSAsend , that use the list for getting WSAOVERLAPPED structure: ... PSLIST_HEADER pListHead; ... PSLIST_ENTRY pListEntry = InterlockedPopEntrySList(pListHead); PPER_IO_CONTEXT ovl = (PPER_IO_CONTEXT)pListEntry; WSASend(pTmp1->Socket,..., &(ovl-

Big O complexity to merge two lists

心不动则不痛 提交于 2020-01-01 15:37:52
问题 Given 2 singly linked lists already sorted, merge the lists. Example: list1: 1 2 3 5 7 list2: 0 4 6 7 10 ---> 0 1 2 3 4 5 6 7 7 10 Despite from the fact that the solution is quite simple and there are several different implementations of the problem with or without using recursion (like this http://www.geeksforgeeks.org/merge-two-sorted-linked-lists/ see Method 3), I was wondering what would be the O big complexity of this implementation: If one of the lists is empty just return the other

Big O complexity to merge two lists

无人久伴 提交于 2020-01-01 15:37:00
问题 Given 2 singly linked lists already sorted, merge the lists. Example: list1: 1 2 3 5 7 list2: 0 4 6 7 10 ---> 0 1 2 3 4 5 6 7 7 10 Despite from the fact that the solution is quite simple and there are several different implementations of the problem with or without using recursion (like this http://www.geeksforgeeks.org/merge-two-sorted-linked-lists/ see Method 3), I was wondering what would be the O big complexity of this implementation: If one of the lists is empty just return the other

Scheme - sum the squares of even-valued elements in a list

十年热恋 提交于 2019-12-29 09:26:12
问题 I want to be able to sum the squares of the even elements in the list, however my current code only sums the elements, not the squares. Does anyone know of any modifications that can be made to make this to sum the squares of the even-valued elements in the list? (define (sum elemList) (if (null? elemList) 0 (+ (car elemList) (sum (cdr elemList))) ) ) My input would be: (sum-evens (list 1 2 3 4)) Output would be: 20 Which is (2*2) + (4*4) . If possible, it would be good to see both a

how to remove a object from linked list in java?

醉酒当歌 提交于 2019-12-29 05:34:11
问题 i have one problem with my code ,i did a sample program to display the emp details from a linked list,now the problem when i trying to delete a particular entry means it doesn't work,i hope i did some mistake in my code could you suggest how to do that? import java.util.*; class EmpDedup { int record; String fprint; int fid; EmpDedup(int record, String fprint, int fid) { this.record = record; this.fprint = fprint; this.fid = fid; } public int getRecord() { return record; } public String