singly-linked-list

Adding in a sorted bag C++

一笑奈何 提交于 2020-05-15 18:22:07
问题 I want to implement the sorted bag(collection) data structure(with a singly-linked list) in C++ and I have a problem when I want to test the add function. This is the test: SortedBag sb(relation1); (relation1 is e1<=e2) sb.add(5); std::cout << sb.size()<<" "; sb.add(6); std::cout << sb.size() << " "; sb.add(0); std::cout << sb.size() << " "; sb.add(5); std::cout << sb.size() << " "; sb.add(10); std::cout << sb.size() << " "; sb.add(8); std::cout << sb.size() << " "; And it will print 1 2 3 3

fix for a reversed link

时光总嘲笑我的痴心妄想 提交于 2020-04-16 05:49:31
问题 hey for some reason my linked list is printing in the reversed ordear for example if my input is 2->4->6 my output is 6->4->2 list* add_int_list(list* a,int b) { list *temp; temp = (list*)malloc(sizeof(list*)); temp->next = NULL; if (a->next == NULL)//insert to the first node { temp->data = b; temp->next = a; a = temp; } else { temp->data = b; temp->next = a; a = temp;//I think the problem is here, couldnt find how to fix } 回答1: For starters in this statement temp = (list*)malloc(sizeof(list*

fix for a reversed link

回眸只為那壹抹淺笑 提交于 2020-04-16 05:49:29
问题 hey for some reason my linked list is printing in the reversed ordear for example if my input is 2->4->6 my output is 6->4->2 list* add_int_list(list* a,int b) { list *temp; temp = (list*)malloc(sizeof(list*)); temp->next = NULL; if (a->next == NULL)//insert to the first node { temp->data = b; temp->next = a; a = temp; } else { temp->data = b; temp->next = a; a = temp;//I think the problem is here, couldnt find how to fix } 回答1: For starters in this statement temp = (list*)malloc(sizeof(list*

How can I get the odd indexed nodes of a linked list in an another linked list?I do not want to use double pointer

岁酱吖の 提交于 2020-03-28 06:46:06
问题 I do not want to use double pointer in my code,please assume index of the first node as 1. I have a linked list 10->20->30->40->50->60->70->80->90->100->NULL In an another linked list whose head pointer is pLink,I want to copy the odd indexed nodes and get the output as 10->30->50->70->90->NULL. SLLI*OddNodes(SLLI*pHead) { int counter =1; SLLI*pTemp=pHead; SLLI*pList=NULL; while(pTemp != NULL) { if(counter % 2 != 0) { if(pList==NULL) { pList=malloc(sizeof(SLLI)); pList->data=pTemp->data;

How can I get the odd indexed nodes of a linked list in an another linked list?I do not want to use double pointer

本秂侑毒 提交于 2020-03-28 06:42:53
问题 I do not want to use double pointer in my code,please assume index of the first node as 1. I have a linked list 10->20->30->40->50->60->70->80->90->100->NULL In an another linked list whose head pointer is pLink,I want to copy the odd indexed nodes and get the output as 10->30->50->70->90->NULL. SLLI*OddNodes(SLLI*pHead) { int counter =1; SLLI*pTemp=pHead; SLLI*pList=NULL; while(pTemp != NULL) { if(counter % 2 != 0) { if(pList==NULL) { pList=malloc(sizeof(SLLI)); pList->data=pTemp->data;

How can I return the odd indexed nodes of a singly linked list in a new singly linked list ?Assume index of the first node as 1

风格不统一 提交于 2020-02-25 06:07:26
问题 When I run this code I am not getting an error message from the compiler but I can not return the new list. Am I writing down the code wrong in the MAIN part? Input 10->20->30->40->50->60->70->80->90->100 Output must be 10->30->50->70->90 #include <stdio.h> #include <stdlib.h> typedef struct SinglyLinkedListItem { int data; struct SinglyLinkedListItem*next; }SLLI; SLLI*OddNodes(SLLI*pHead) { int counter =1; SLLI*pTemp=pHead; SLLI*pList=NULL; while(pTemp != NULL) { if(counter % 2 != 0) { if

How can I return the odd indexed nodes of a singly linked list in a new singly linked list ?Assume index of the first node as 1

假如想象 提交于 2020-02-25 06:05:11
问题 When I run this code I am not getting an error message from the compiler but I can not return the new list. Am I writing down the code wrong in the MAIN part? Input 10->20->30->40->50->60->70->80->90->100 Output must be 10->30->50->70->90 #include <stdio.h> #include <stdlib.h> typedef struct SinglyLinkedListItem { int data; struct SinglyLinkedListItem*next; }SLLI; SLLI*OddNodes(SLLI*pHead) { int counter =1; SLLI*pTemp=pHead; SLLI*pList=NULL; while(pTemp != NULL) { if(counter % 2 != 0) { if

How do I change a singly-linked list to a doubly-linked list?

自闭症网瘾萝莉.ら 提交于 2020-02-07 11:34:14
问题 I'm currently taking a Java class and the professor told us that a good practice to understand links would be to make a doubly linked list. I have made a singly linked list but I am having trouble converting it to a doubly linked list. So I was wondering if anybody could give me any suggestions on making sure my last number is connected to the previous one? And if the front number and last number connected to the null. Here is part of the code, if you wish for more of it just ask and I shall

How do I change a singly-linked list to a doubly-linked list?

点点圈 提交于 2020-02-07 11:27:13
问题 I'm currently taking a Java class and the professor told us that a good practice to understand links would be to make a doubly linked list. I have made a singly linked list but I am having trouble converting it to a doubly linked list. So I was wondering if anybody could give me any suggestions on making sure my last number is connected to the previous one? And if the front number and last number connected to the null. Here is part of the code, if you wish for more of it just ask and I shall

How do I change a singly-linked list to a doubly-linked list?

强颜欢笑 提交于 2020-02-07 11:26:12
问题 I'm currently taking a Java class and the professor told us that a good practice to understand links would be to make a doubly linked list. I have made a singly linked list but I am having trouble converting it to a doubly linked list. So I was wondering if anybody could give me any suggestions on making sure my last number is connected to the previous one? And if the front number and last number connected to the null. Here is part of the code, if you wish for more of it just ask and I shall