linked-list

Implementing fa unction that adds and sorts data in a singly linked list (addsort)?

不打扰是莪最后的温柔 提交于 2019-12-12 01:59:59
问题 I'm very new to C++ so it's a bit hard to understand the syntax sometimes. Anyways, I'm supposed to implement a function that adds and sorts the data given into a linked list. For example if I pass 2 into the list [1,4,5] then I should get [1,2,4,5] Here is what I have written so far, and no it does not work, I keep getting "blah blah not declared in this scope" void addSorted(Data * ){ temp = 0; if (head == NULL) { head = new LinkNode(newData); } else { LinkNode * current = head; while

Linked Lists in C. error: conflicting types. Solution?

本秂侑毒 提交于 2019-12-12 01:43:23
问题 i have the following struct defined: typedef struct PList{ Person person; struct PList *nextPerson; // set to NULL by default <<<<< }PList; and this method: int length(struct PList* db){ PList* cur = db; int size = 0; while (cur != NULL){ ++size; cur = cur->nextPerson; } return size; } error: conflicting types for 'length' is being thrown at the signature for the length method. Any ideas? 回答1: That actually means that there is another function/declaration called length elsewhere in your

Implementing a new LinkedList method in Java

那年仲夏 提交于 2019-12-12 01:37:44
问题 I have an assignment that involves creating three methods that manipulate a linked list. The instructions dictate that I use the following constructor: public MyList (LinkedList<Integer> list) { ... } However, Eclipse seems to not like my code regardless of how I try integrate it. Here's my current attempt: import java.util.*; public class ListClass { public static void main(String[] args) { LinkedList<Integer> list = new LinkedList<Integer>(); list.add(10); list = MyList(list); } public

Error: unknown type name List when trying to create a Linked List

只愿长相守 提交于 2019-12-12 01:37:42
问题 So I'm new to C and am trying to create my linked list. But for some reason I keep getting this error: unknown type name List . This is what I have so far: struct Node{ int data; struct Node *next; }; struct List{ struct Node *head; }; void add(List *list, int value){ if(list-> head == NULL){ struct Node *newNode; newNode = malloc(sizeof(struct Node)); newNode->data = value; list->head = newNode; } else{ struct Node *tNode = list->head; while(tNode->next != NULL){ tNode = tNode->next; }

Why is this C linked list program giving 'segmentation fault'?

ⅰ亾dé卋堺 提交于 2019-12-12 01:33:50
问题 The first function reads a file that has a bunch of 'char's and puts them in a linked list. It is not working :(. #include <stdio.h> #include <stdlib.h> struct list { char val; struct list* next; }; typedef struct list element; int lcreate(char* fname, element* list); int ldelete(element* list); int linsert(char a, char b, element* list); int lremove(char a, element* list); int lsave(char* fname, element* list); int lcreate(char* fname, element* list) { element* elem = list; char c = 0; FILE

Single linked lists in C

痴心易碎 提交于 2019-12-12 01:18:27
问题 I'm basically trying to create a linked list from a text file and add a new member every time the words are different, and increment the count if the words are the same (hw assignment). I thought I did it correctly, but it seems to add a member no matter what. I'm wondering if I'm traversing the list incorrectly while I search? Here is my code. Any thoughts? Thanks! LIST *CreateList(FILE *fp) { char input[LINE_LEN]; LIST *root= NULL; /* contains root of list */ size_t strSize; LIST *newList;

Bubble sort Linked list C++

这一生的挚爱 提交于 2019-12-12 01:16:36
问题 I'm having problems with this code. I'm pretty sure it's in the swapping. The line: curr->Data() = nextEl.Data() gives me the following error: "expression must be a modifiable lvalue" Any help is appreciated. Thank you in advance. Here is the code for my bubble-sort algorithm: class Node { private: int data; Node* next; public: Node() {}; void Set(int d) { data = d;}; void NextNum(Node* n) { next = n;}; int Data() {return data;}; Node* Next() {return next;}; }; class LinkedList { Node *head;

Remove a node in LinkedList in Java given the node reference

六眼飞鱼酱① 提交于 2019-12-12 01:11:58
问题 For example, if I have LinkedList LinkedList<Integer> ll = new LinkedList<Integer>(); ll.add(1); ll.add(2); ll.add(3); Integer x = new Integer(10); ll.add(x); ll.add(4); // now the list looks like 1->2->3->10->4 // what if I want to remove 10 and I still have the reference to that node x // what is the API of that // somethings like ll.remove(x)... If I implement a doubly linked list by myself, just currentNode.prev.next = currentNode.next; currentNode.next.prev = currentNode.prev; Does Java

Delete Node from linkedlist

匆匆过客 提交于 2019-12-12 01:04:04
问题 I wrote a phone book it can search among entities now I wrote a delete function but I don't know how to use it in a good manner if I call search and then delete it how? i should give a flag on search function? I want to when user entered any Number,Email,... if there exists delete it I don't know my function in delete is correct or not suppose for the first time the linked list is not empty #include <stdio.h> #include <string.h> #include <ctype.h> #include <stdlib.h> struct node { char Number

insert in Linked List Turbo C

折月煮酒 提交于 2019-12-12 00:42:39
问题 I am trying to program a text editor in C. I am having trouble with inserting an element in a linked list. The program simply won't insert anything in the middle of the linked list. #include <stdio.h> #include <stdlib.h> #include<conio.h> I used singly linked list. struct node { struct node *previous; int c; int x; int y; struct node *next; }*head; this works fine: void characters(int typed, int xpos, int ypos) //assign values of a node { struct node *temp,*var,*temp2; temp=(struct node *