linked-list

linked list insertion sort in c

烈酒焚心 提交于 2019-12-11 10:15:52
问题 the program should do the insertion ascending sort for the nodes,first it should check the names and if the names are equal it should sort the ids,i do not know what is the issue that does not sort properly. # include <stdio.h> # include <string.h> # include <stdlib.h> typedef struct nd{ int id; char name[20]; float gpa; struct nd *next; }node; typedef node *list; //--------------------------------------------------------------- int insertlist(list *head,char *buffer) { list p,q,n; int m,num

C++ Linked list with Objects that is coming up with the LNK2019 error

 ̄綄美尐妖づ 提交于 2019-12-11 10:10:07
问题 Basicaly this is my assignment project for C++ and i'm pretty new to C++ and i'm getting this error up. Also having an error for the commented code in main == is not a matched operand 1>Main2.obj : error LNK2019: unresolved external symbol "class std::basic_ostream > & __cdecl operator<<(class std::basic_ostream > &,class Customer &)" (??6@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV01@AAVCustomer@@@Z) referenced in function "void __cdecl display(struct Node *)" (?display@@YAXPAUNode

Accessing an element within my custom linked list class

妖精的绣舞 提交于 2019-12-11 09:57:09
问题 I'm building my own linked list class and I'm having some issues figuring out how to write some functions to help me traverse this list. This is my first time building a linked list from scratch, so if my approach is unconventional please let me know what might be more conventional. I'd like write a function, within the List class that allows me to increment to the next element called getNext() as well as one that getPrev(); I wrote getNext like this: T* getNext(){return next;} However it

Reading file Line By Line in C

心已入冬 提交于 2019-12-11 09:56:19
问题 Preface: This question is about reading a file, line by line, and inserting each line into a linked list. I have already written the implementation for the linked list, and tested the insert() function manually. This works. I have also written the code for reading text from a file, and writing it out. Again, this also works. OKAY: HERE'S MY QUESTION How can I merge these concepts, and write a function that reads text from a file, line by line , and inserts each line as a node in the linked

How to avoid down-casting when return types are not known at compile time?

送分小仙女□ 提交于 2019-12-11 09:54:37
问题 Suppose I have a abstract base class called Node . class Node { public: Node() { leftChild = NULL; rightChild = NULL; }; Node * leftChild, *rightChild; void attach(Node * LC, Node * RC) { leftChild = LC; rightChild = RC; }; }; I also have multiple functions (of which I'll include two for simplicity but in reality this could be any number). float add(float a, float b){return a+b;} bool gt(float a, float b){return a>b;} For each function there is an associated class. The first is as follows.

How to swap index for a linked list C++ [duplicate]

感情迁移 提交于 2019-12-11 09:29:10
问题 This question already has answers here : Correctly implementing a singly linked list C++ (4 answers) Closed 6 years ago . I have the out put: node 1: Bob Joe Jill Jeff Jill but I want it to where if a name repeats that gets sent to the front of the singly linked list, so it would become node 1: Jill Bob Joe Jeff And I'm having trouble being able to implement that. Here's my code: string employers[] = {"Jill", "Jeff", "Bob", "Joe", "Monica", "Luis"}; struct node { node(string name="") {data

Deleting a single linked list by just making head = null?

好久不见. 提交于 2019-12-11 08:56:43
问题 Why can't I just make head=null to delete the complete Linked list? 3 = head > 1 > 2 > 4 > null By making head = null , JVM will take care of it.As head node is not referenced by any variable , it should be garbage collected. What is wrong with this solution? Note: I'm aware of the correct solution to delete the complete link list but I'm curious why I can't just make head=null to delete the complete linked list? 回答1: Here's the code of java.util.LinkedList.clear(), verbatim: public void

C: fgets usage for building a linked list of char*

不问归期 提交于 2019-12-11 08:48:50
问题 Am I using fgets() incorrectly? I am trying to build a linked list of strings ( char * ) adding each new line to the end of the LL. I am reading these lines from a file, but for some reason every line gets overwritten by the current line being processed, only when using fgets() inside the while loop, but the add function seems to be receiving each line correctly. If I add lines individually in main() there are no problems. Here is a sample input file: input.txt: This life, which had been the

How will you delete duplicate odd numbers from a linked list?

丶灬走出姿态 提交于 2019-12-11 08:44:09
问题 Requirements/constraint: delete only duplicates keep one copy list is not initially sorted How can this be implemented in C? (An algorithm and/or code would be greatly appreciated!) 回答1: If the list is very long and you want reasonable performances and you are OK with allocating an extra log(n) of memory, you can sort in nlog(n) using qsort or merge sort: http://swiss-knife.blogspot.com/2010/11/sorting.html Then you can remove duplicates in n (the total is: nlog(n) + n) If your list is very

Testing if a linked list is equal to each other

喜夏-厌秋 提交于 2019-12-11 08:36:15
问题 I have a set of numbers that are in a linked list. I want to compare them to see if they are the same numbers in a set. Here is my code right now: bool set::equalset(set second) { Data *travel1, *travel2; travel1 = top; travel2 = second.topval(); //gets the top value for the second set while (travel2->next != NULL && travel1->next != NULL) { if (!in(travel2->value)) //in checks if the value is in the set return false; if (!second.in(travel1->value)) //same idea here return false; travel2 =