linked-list

compilation error: request for member in something not a structure or union

匆匆过客 提交于 2019-12-01 15:47:10
问题 Edit: The code below has been modified to work as the problem has been solved. Specifically, (*hardwareList.next_item)->next was originally written without brackets (e.g. as *hardwareList.next_item->next ) and the compiler didn't understand it. I'm trying to workout why the compiler is getting confused with my C code. I'm trying to create a linked list that stores all the items and also a pointer to the address-of the last "next" variable, for easy appending. typedef struct { int recordNum;

Printing my linked list in reverse order in C++

旧巷老猫 提交于 2019-12-01 14:54:00
问题 So I'm fairly new to C++ and today I decided to sit down and understand how linked lists work. I'm having a lot of fun doing it so far, but I've encountered a problem when trying to print my linked list in reverse order (not reverse the order of the linked list!) Also, I wanted to do this without having a double linked list: #include <iostream> #include <string> using namespace std; class LinkedList { public: LinkedList() { head = NULL; } void addItem(string x) { if(head == NULL) { head = new

Save distinct words into linked list

爷,独闯天下 提交于 2019-12-01 14:49:36
Basically I have 2 linked list here: list and distinct. There are a few set of words which have been saved earlier into the 'list' struct. Was gonna write a program that is gonna find the words that are distinct/unique and save it into the 'distinct' struct. Here is what I got so far based on my concept on pointers. However when I try to print 'distinct', the program crashes :( please correct me if I'm wrong. struct list { char string[50]; struct list *next; }; struct distinct { char string[50]; struct distinct *next; }; void checkdistinct() { list *ori = NULL; distinct *copy = NULL; distinct

Merge two sorted link lists

筅森魡賤 提交于 2019-12-01 14:36:50
I wanted to merge two sorted link lists by pointer manipulation, but stuck at this point. cant find out the mistake. Help me please. I think the problem is in while loop. I want to make it space efficient and do not want to make another list. #include<iostream> #include<conio.h> using namespace std; struct s { int info; s *next; }; int main() { int i; char choice = 'y'; s *ptr1, *ptr2, *start1, *start2, *reversedHead, *temp; ptr1= new s; start1=ptr1; cout<<"SIZE OF A NODE IS "<<sizeof(s)<<" BYTES"<<endl<<endl; while(choice=='y') { cout<<"Enter info for node: "; cin>>i; ptr1->info = i; cout<<

Reversing a linked list

允我心安 提交于 2019-12-01 14:24:13
问题 Problem in Reversing a linked list without using recursion. I used this method, but when i try and run this back home, I am not able to print the reverse of the linked list even though the function looks good It goes on to print the linked list in the same way as it did earlier. Can someone help me understand what is wrong here?? class link { int data; public link nextlink; link(int d1) { data = d1; } } class List{ link head; link revhead; List(){ head = null; } boolean isEmpty(link head) {

debug help - swap 2 nodes of double link list

纵然是瞬间 提交于 2019-12-01 14:19:13
Could you please help me debug this code to swap two node of double link list? I am not able to figure out what i am doing wrong :( here is the code: dll* swap_node(dll *head , dll *node1 , dll *node2) { dll *tmp; int flag=0; if(node1->prev!=NULL) { node1->prev->next=node2; } else { flag=1; } if(node1->next!=NULL) { node1->next->prev=node2; } if(node2->prev!=NULL) { node2->prev->next=node1; } if(node2->next!=NULL) { node2->next->prev=node1; } tmp=node1->next; node1->next=node2->next; node2->next=tmp; tmp=node1->prev; node1->prev=node2->prev; node2->prev=tmp; if(flag==1) { head=node2; } return

Save distinct words into linked list

喜你入骨 提交于 2019-12-01 13:30:35
问题 Basically I have 2 linked list here: list and distinct. There are a few set of words which have been saved earlier into the 'list' struct. Was gonna write a program that is gonna find the words that are distinct/unique and save it into the 'distinct' struct. Here is what I got so far based on my concept on pointers. However when I try to print 'distinct', the program crashes :( please correct me if I'm wrong. struct list { char string[50]; struct list *next; }; struct distinct { char string

Sorting a Doubly Linked List C++

こ雲淡風輕ζ 提交于 2019-12-01 13:29:56
Trying to do it through a loop that traverses through the list. In the loop I'm feeding the head node into a sorting function that I have defined and then I'm using strcmp to find out if which name in the node should come first. It is not working because writing the names too early. Im comparing them all linearly by going down the list one node at a time and not going back to see if the first should come before the last. That part explained would be helpful. The two functions that are most important to me now are defined as follows: I have tried my best to do what I think is right for the

SLinkedList and Node in Java

这一生的挚爱 提交于 2019-12-01 13:23:12
To start with, yes, this is for an assignment in class, but my lack of understanding on how it operates is higher than I want it to be. We were given 3 classes, they are the following: SLinkedList.java package chapter3.linkedList; public class SLinkedList<V> { // instance variables. Add the tail reference. protected Node<V> head, tail; protected long size; // methods, empty list constructor first public SLinkedList () { head = null; tail = null; size = 0; } // end constructor of a SLinkedList // method to add nodes to the list. Storage space for the node // is already allocated in the calling

Merge two sorted link lists

此生再无相见时 提交于 2019-12-01 13:01:00
问题 I wanted to merge two sorted link lists by pointer manipulation, but stuck at this point. cant find out the mistake. Help me please. I think the problem is in while loop. I want to make it space efficient and do not want to make another list. #include<iostream> #include<conio.h> using namespace std; struct s { int info; s *next; }; int main() { int i; char choice = 'y'; s *ptr1, *ptr2, *start1, *start2, *reversedHead, *temp; ptr1= new s; start1=ptr1; cout<<"SIZE OF A NODE IS "<<sizeof(s)<<"