Questions tagged [linked-list]
The linked-list tag has no usage guidance.
49
questions
1
vote
1
answer
85
views
Lecture 5 Linked Lists: What's going on under the hood?
Sheepishly I must admit I am having difficulty understanding how Linked Lists are implemented. Spent an hour and a half just on this part. The following partial code is from the lecture (comments ...
0
votes
1
answer
135
views
Inserting node in linked list
I'm attempting to create a linked list in C to practice the concepts of pointers and data structures. I keep running into a segmentation fault and I've narrowed down the issue to my insertNode() ...
0
votes
1
answer
19
views
PSet 5 Speller - Expected Identifier
Been stuck on Speller for 2 days and could really please use some help.
My initial idea is just to create an array of linked lists with 26 buckets (N = 26) and very simply hash the words by only the ...
0
votes
2
answers
48
views
Linked list, List isn't passing by reference?
I've really been struggling with PSET5 so I decided to take a step back and write a simple linked list program. My program take in an array of characters as a command line argument and stores each ...
0
votes
1
answer
25
views
I don't get why the pointer to next in the node is "new" and not "head", can someone please explain?
I'm practising using Linked Lists, and trying some exercises here:
https://study.cs50.net/linked_lists
Here's an exact copy-paste of the code found at the bottom:
#include <assert.h>
#...
0
votes
1
answer
318
views
Pset 5 Speller Linked List Nodes
I thought I got pointers but I don't fully understand a function that gets a new node for a linked list. I understand the theory behind Hash tables and chaining with linked lists but when it comes to ...
0
votes
1
answer
52
views
on pset4 speller load() struggling to understand if populating dictionary correctly and how to check hashtable
I am building my load() function and I'm wondering if I'm building it so that it is indeed storing the dictionary words correctly.
I tried printing both:
printf("%s\n", new_node->word); //to see ...
0
votes
1
answer
93
views
Declaring a typedef struct for linked list
In Lecture 4, David uses this to declare a node struct:
typedef struct node
{
int n;
struct node *next;
}
node;
However, in shorts after Lecture 4, Doug explicitly tells us that when ...
0
votes
1
answer
19
views
Help in linked datastructure
I have tried to rewrite what David said in the lekture, but cant print out my values and do not know how. I have tried to make a for look but didnt work either.
#include <stdlib.h>
#...
0
votes
2
answers
1k
views
pset4 Speller hash table basics
After struggling with this pset for a while I decided to strip it down to its most basic form and try and understand the implementation of hash tables and linked lists by creating my own. To that end ...
0
votes
1
answer
24
views
Why am I able to insert an element into a hash tree via Main() but not via a function call?
I'm fairly certain this has something to do with pointers and the function using copies instead, but I'm not sure how...because I've inserted the pointer as a parameter for create();
#include <...
0
votes
1
answer
54
views
load function pset5; segmentation fault tackled?
This is the code for my load function
bool load(const char *dictionary)
{
//open dictionary
FILE *inptr = fopen(dictionary, "r");
if (inptr == NULL)
{
fprintf(stderr, "Could not open %s.\n", ...
0
votes
1
answer
39
views
checking structure of a hash table? pset5 dictionary
I am currently working on the load dictionary function of pset5.
I was wondering if anyone has any suggestions for how to go about checking if the organization of one's hash table and the sorting of ...
0
votes
1
answer
132
views
HashTable full of single value
I think the problem is in my load function. I am able to successfully create a hash for each word, and I can call my createNode and insertNode functions to such a degree that I create a full hashtable ...
0
votes
1
answer
224
views
Help with singly linked list basics
I've been at this for awhile; linked lists have always been a problem. By this I mean, I've already watched the shorts and done a ton of reading. A ton.
Below is how I'm trying to think about reading ...
0
votes
1
answer
115
views
Two hash table questions
I am working through SPELLER and have a few questions. When I create a new node node *newptr = malloc(sizeof(node)); do I need to say newptr1, newptr2, newptr3 and if so what is the best way of doing ...
0
votes
1
answer
717
views
Struggling with hash table! Pset5
I've been trying to fix this bug for the past couple of days, but it seems this one I really can't figure out on my own. Hope you guys can help a bit.
Here's the code for my load function in pset5.
#...
0
votes
1
answer
93
views
PSet5 Hash Tables
I was learning how to create an array of linked lists for the pset5 problem. But i keep getting a segmentation fault when I go through a character linked lists a second time. Some kind of address keep ...
0
votes
1
answer
43
views
INT_MAX not working?
I was just trying to implement the linked list i.e. simply just entering the numbers until the EndOfFile using INT_MAX and then printing them
#include <cs50.h>
#include <stdio.h>
...
0
votes
1
answer
287
views
deleting first element of a linked list
By this code I can't delete the first element of my linked list. Can anybody tell me how to fix it
// defining the linked list (basics)
#include <stdio.h>
#include <stdlib.h>
struct ...
0
votes
1
answer
185
views
Singly Linked list basic
I had written the code just to create a linked list but it's showing segmentation fault. Can anybody tell me what's the mistake and what should I do to resolve it
My code for the singly linked list
/...
0
votes
1
answer
133
views
Linked lists & pointers
In pset 5s walkthrough, the node struct is defined like this:
typedef struct node
{
int value;
struct node* next
} node;
And when we then use the cursor -> next statement, to jump to the ...
0
votes
1
answer
1k
views
Destroy function with Single linked list
Still having problems understanding how to free the memory for a single linked list. I went over the presentation and put together this snippet of code:
void destroy(sllnode* head)
{
// *base case* ...
0
votes
1
answer
135
views
I am working since past 4days on pset5 (speller) .All the words of dictionary are shown as mispelled. Please help me out. Thank You
My code misspells all the words of the text file.I have not made a single change to speller.c as mentioned in the instruction.I seem to have found out (using debug50) that my hash table is not getting ...
0
votes
1
answer
30
views
Having a bit of a problem with linked lists. Need someone to look at code
Here is my code. I seem to be doing something wrong and am getting multiple compilation errors but feel that it has got something to do with one thing alone. Kindly help.
https://pastebin.com/...
1
vote
1
answer
335
views
How does HEAD in linked list work?
I still can't figure out how HEAD in linked list works.
What type of data is head?
How can head be linked (connected) to the first note?
That is what I have written, but still, don not know how to ...
0
votes
1
answer
92
views
singly-linked list issues
this is not directly related to the problem set, but maybe somebody can help me out nevertheless. I'm trying to understand the singly-linked list and so I've attempted to write one on my own, based on ...
0
votes
1
answer
72
views
creating linked list, problem understanding code
I am trying to write comments to understand a program to implement inserting a node at nth position
I am not able to understand the last line in insert function
temp2->next = temp1; //??temp 1 that ...
0
votes
1
answer
272
views
Insert a node at the beginning of an existing linked list
The following code tries to add a node to the beginning of a linked list.
Can anyone explain to me why my insert function doesn't work? The program passed in a pointer nodePtr and modified it inside ...
0
votes
1
answer
166
views
Do I have to declare 26 Heads if my hashtable is of size 26?
I have just started pset5 and for the implementation of the function load i was practicing on the smaller dictionary with making another .txt file and filling it with 3 words for each alphabet, The ...
0
votes
1
answer
168
views
Kinda confused with what needs memory allocated in pset5
I wanted to give hashtables a go with pset5. I've set the struct up as:
typedef struct node {
char *data;
struct node *next;
} node;
Every time I link a new node all of the node->data ...
0
votes
1
answer
103
views
Trouble Interpreting Linked List Sample Code - PSET5
I'm having trouble interpreting the code for a linked list of students passed out as preparation for pset5, and would like to know if someone could explain what I am missing.
The structs are as ...
1
vote
1
answer
718
views
Recursion Destroy Singly linked List, memory leak?
I'm working through some personal test code to make sure I understand how to work withs singly linked lists.
I'm basically going through the Week 5 Section video on singly linked lists and putting ...
0
votes
1
answer
392
views
Speller check keeps returning all mispelled words
I have looked over a bunch of posts on speller.c load but I cannot figure out what I am doing wrong here. My load function seems to be working well as a linked list. My check function keeps ...
0
votes
1
answer
294
views
The load function in dictionary.c is segfaulting. 3 tfs have looked over my code and none can figure out what's going on. Can anyone help?
This is how I've implemented my load function:
bool load(const char* dictionary)
{
// Open file
FILE* input = fopen(dictionary, "r");
if (input == NULL)
{
return false;
}
...
0
votes
1
answer
62
views
Linked list doesn't print out the correct values (when using fopen)
When I run following program with a list of 5 words I keep getting an output of last last last last last opposed to last fourth third second first (ie the contents of the word list which I am ...
2
votes
1
answer
137
views
adding data to singly linked list
I'm trying to wrap my head around linked lists (which I will call SLI for now) and tries
I was wondering if anyone could confirm following (or explain where I my reasoning is wrongg)
In a SLI, you ...
0
votes
2
answers
110
views
inserting a node in the middle of a linked list failed
I'm trying to implement an insertion function to insert nodes in a linked list.(using the code written in study 50) the program appends and prepend nodes successfully but when it comes to inserting a ...
0
votes
1
answer
134
views
Insert data at head node linked list
Just for the understanding purpose i have posted two functions & code is in C++. Trying to insert each node as head and link that node to the previous one but while loop goes infinite while ...
0
votes
1
answer
62
views
inserting elements in a linked list (sorted)
I want to implement an insertion function on cs50 study but it doesn't work right. the program doesn't output the numbers I inserted. all i am sure about is that the problems is with my function .i ...
1
vote
1
answer
318
views
How to add a new node in the linked list
Now that I am done with pset5 I would like to understand how to add a new node to a linked list. While building the pset, I blindly used Zamyla's guidelines on how to add a new node to a linked list ...
0
votes
1
answer
37
views
Segmentation error with array of nodes
I don't understand why I am getting segmentation error. Is it because I'm setting the array to NULL? Though if I don't set it to NULL then the head of the list will always keep the value of zero.
...
1
vote
1
answer
891
views
how to read integers (separated with spaces) from a file line-wise?
I have a file filled with integers and these integers are separated with spaces and a new line. This means that there are a bunch of integers per line. I want to read each line of integers and store ...
6
votes
1
answer
93k
views
How to fix the "conditional jump or move depends on uninitialized value" valgrind error?
Need help again.
I've got my linked list working. It copies a list of words from a file into a linked list.
Now I want to make a hash table so that all words starting with the letter 'A' go into a ...
0
votes
1
answer
240
views
Linked List not working contd. Valgrind Error
The program is supposed to read the words of a file to a linked list. I got the Linked list working but now I'm faced with another error. I'm getting a segmentation fault when using a very large file. ...
0
votes
1
answer
807
views
C Linked List not working
I want to read the words of a file into a linked list. The file contains two words: cat & caterpillar.
However, the output of my linked list just spits out caterpillar twice. Something somewhere ...
0
votes
1
answer
108
views
strcmp node->value
Why strcmp(value,curr->value) returns always 0?
I'm using a code like this:
char buffer[LENGTH+1] = {};
while(fscanf(inptr, "%s", buffer) > 0)
{
insert( hashtable, buffer );
}
Then, inside ...
0
votes
1
answer
110
views
PSET6: Sorted List?
I just finished pset6 following the videos of Zamyla and the section. At the end I realized that my code implements a sorted linked list (via strcmp) but then I don't take advantage of that in my ...
2
votes
2
answers
2k
views
implementation of hash table
I have been having trouble with the implementation of the hash table and linked lists. I don't know if I am on the right track or not, but I think my main problem is not knowing how to automate the ...