linked-list

Reading from file to dynamic struct

强颜欢笑 提交于 2020-01-06 14:01:26
问题 I would like to read from a file, line by line. Each line has 3 arguments guaranteed. First 2 are first and last name and third is age. I want to make a linked list, in which, each node represents a person (line) in the file. I don't know the size of the names so I made it dynamic. I also don't know the number of lines in the file, so I would like that to be dynamic too. My approach was to use fscanf, but then I wouldn't know how much memory needs to be allocated prior to reading it. The

Reading from file to dynamic struct

大兔子大兔子 提交于 2020-01-06 13:59:30
问题 I would like to read from a file, line by line. Each line has 3 arguments guaranteed. First 2 are first and last name and third is age. I want to make a linked list, in which, each node represents a person (line) in the file. I don't know the size of the names so I made it dynamic. I also don't know the number of lines in the file, so I would like that to be dynamic too. My approach was to use fscanf, but then I wouldn't know how much memory needs to be allocated prior to reading it. The

Using linked list in C

我的梦境 提交于 2020-01-06 13:56:50
问题 I'm new to the linked list topic and I just created my first program using linked lists, the problem is it's not saving any data to the structure. It runs fine, no error, but when printing no data is displayed. Here is my code. #include <stdio.h> #include <stdlib.h> #include <string.h> struct node { int nID; char chTitle; struct node* next; }; void addList(struct node *head); void printList(struct node *head); int checkID(struct node *head, int t); int main(int argc, const char * argv[]) {

Heap Sort a Linked List

六月ゝ 毕业季﹏ 提交于 2020-01-06 12:41:30
问题 I'm trying to create a sort function in c++ that sorts a linked list object using Heap sort but I'm not sure how to get started. Can anyone give me any idea on how to do it ? I'm not even sure how I would sort a Linked List 回答1: Heapsort works by building a heap out of the data. A heap is only efficient to build when you have random-access to each element. The first step is going to be creating an array of pointers to your list objects, so you can perform the usual heap sort on the array. The

Delete node from linked list with specific value

人走茶凉 提交于 2020-01-06 08:19:23
问题 I am currently writing a program that has a function that needs to delete a node based on its value. I have tried and tried to figure it out. All I have so far is the function signature: NODE* delete_node(NODE * ptr, int n, int *success_flag) My linked list as the follow structure: /* declaration of structure */ typedef struct node { int data; struct node *next; } NODE; Heres some of the code I already have regarding another concerns: #include <stdio.h> #include <stdlib.h> /* declaration of

Why does Java compiler give “error: cannot find symbol” for LinkedList descendingIterator in the following code?

余生长醉 提交于 2020-01-06 08:05:21
问题 Why does this code: import java.util.*; class Playground { public static void main(String[ ] args) { List<Integer> l = new LinkedList<>(); Iterator<Integer> i = l.descendingIterator(); } } Generate this compiler error ./Playground/Playground.java:5: error: cannot find symbol Iterator<Integer> i = l.descendingIterator(); ^ symbol: method descendingIterator() location: variable l of type List<Integer> 1 error Here is the relevant JavaDocs API Running Java 7.. In case that is issue. Thought it

Recursively add a node at a certain index on Linked List

拟墨画扇 提交于 2020-01-06 07:28:08
问题 I'm trying to add a list node at a specified index recursively. By that I mean the List class addAtRec() calls addAtRec() in the ListNode class, that method is supposed to be recursive. This is what I did: List: public class List implements Cloneable { private ListNode firstNode; private ListNode lastNode; private String name; private int counter; public List(){ this("list"); } public void addAtRec(Object obj, int k) { if(firstNode != null) firstNode.addAtRec(obj, k, firstNode); } } That's of

Remove function in a Linked List

僤鯓⒐⒋嵵緔 提交于 2020-01-06 07:14:34
问题 I have a header file called StringList.h that includes the following: #include <string> using namespace std; class StringList; class StringListNode { friend class StringList; private: StringListNode * pPrev; string data; StringListNode * pNext; }; class StringList { public: StringList(); ~StringList(); void addToBottom(string s); void addToTop(string s); void remove(string s); string print(); void clear(); bool isEmpty() {return (pTop==NULL);} private: StringListNode * pTop; StringListNode *

pointers N linked list in C

帅比萌擦擦* 提交于 2020-01-06 05:42:05
问题 I wrote to following code which does not work. The application crashes on the print method. Any idea where it goes wrong? #include <stdio.h> #include <stdlib.h> typedef struct { int item; struct LinkedList *Next; } LinkedList; int main() { LinkedList vaz; vaz.item = 14123; vaz.Next = 0; add(&vaz,123); add(&vaz,9223); Print(&vaz); return 0; } void Print(LinkedList* Val) { if(Val != 0){ printf("%i\n",(*Val).item); Print((*Val).Next); } } void add(LinkedList *Head, int value) { if((*Head).Next =

C - Linked List - how to assign and go through the list

蹲街弑〆低调 提交于 2020-01-06 05:22:06
问题 i'm having trouble with building a linked list using two structs node - contains data and pointer to the next, and list which contains pointer to the head of the list. i managed to implement it with only the node struct. i have initialized a struct of a list in the main function than allocated memory for a list struct using malloc than i allocated memory for the head which is a pointer to the first node sent it to another function where there the input,allocating,assigning goes, but im having