2
votes
Accepted
How does HEAD in linked list work?
Your question is unclear, but I'll take a shot at it. In a linked list, HEAD is usually a var name, not a data type. HEAD is usually a pointer or possibly a data structure that serves as the pointer ...
2
votes
Accepted
Insert a node at the beginning of an existing linked list
head is passed per value, therefore it's a copy of the pointer you try to update. For updating the original value, either return the new head and update global head by assignment, or pass a reference (...
1
vote
Accepted
Inserting node in linked list
In your insertNode function, while your iterating to find the last node, you should check whether the next_node is NULL, not current_node is NULL.
Let's say, we had two nodes
1 -> 2 -> ...
1
vote
Accepted
Pset 5 Speller Linked List Nodes
Maybe there are a couple things that you haven't grasped yet.
First, creating a var and initializing a var are two very different actions.
A statement like node *pnode; creates a node var called ...
1
vote
Accepted
in speller load() struggling to understand if populating dictionary correctly and how to check hashtable
Start with a smaller dataset (dictionary). Keeping track of 143K+ nodes is a job for a computer, not a human. And remember, the same file can be used as both dictionary and text, so dictionaries/small ...
1
vote
Accepted
Declaring a typedef struct for linked list
The requirement is that you give the struct a name so you can use it in the declaration. Whether or not that is a different name isn't important. Both of those declarations are fine.
1
vote
Accepted
Help in linked datastructure
You seem to ignore the value of found. Just disables the duplicate check.
You don't have a loop for printing elements, and you seem to use ptr before initialisation. I would expect a loop very ...
1
vote
Accepted
pset4 Speller hash table basics
Without seeing exactly what the new code looks like (certain important aspects may be missing from your description), it's still pretty obvious what happened.
In the pointer implementation, a new ...
1
vote
Accepted
HashTable full of single value
You allocate space for one word. Then you copy its address to all your value pointers. Of course it's all the same word, as you re-use the same space all the time.
I used a char value[LENGTH + 1] ...
1
vote
Accepted
Help with singly linked list basics
Believe it or not, your problem isn't with linked lists, it's with pointers. Let's see if I can walk you through this.
First, every word (line) is being stored in the char array line[100] as its ...
1
vote
Accepted
Two hash table questions
Hash tables are basically arrays of pointers, and the hash determines the index to use. Each of those pointers points to the first node of a linked list (or similar). A node of a linked list consists ...
1
vote
Accepted
Struggling with hash table! Pset5
new->word = dWord;
I'd say that the address of dWord is being copied into the pointer(s) new->word for every node created, and not the actual word. When every word is processed, it is written ...
1
vote
Accepted
PSet5 Hash Tables
It's always the simple ones that hide in plain sight. ;-) Look very carefully at this:
Node* temp = malloc(sizeof(Node*));
The code allocates memory space that is sizeof what? A node or a pointer?...
1
vote
Accepted
deleting first element of a linked list
Deleting a node from a linked list requires changing the pointer to this node. So it might be useful to have a pointer to the head pointer, like
void del(struct node **head_ptr, int data)
{
...
1
vote
Accepted
Singly Linked list basic
You assign to temp, which is a local variable, the node never ends up in the linked list.
I'd use pointers to pointers all the time, for example like
void create(struct node **head, int data)
{
...
1
vote
I am working since past 4days on pset5 (speller) .All the words of dictionary are shown as mispelled. Please help me out. Thank You
fscanf(file , "%s" , word)
By design, fscanf automatically put '\0' in the end. So if it reads cat\n, the result is cat\0.
By doing this:
word[strlen(word) - 1] ='\0'
you overwrite the last char ...
1
vote
Accepted
Having a bit of a problem with linked lists. Need someone to look at code
The problem is that you are trying to make assignments that are dependent on runtime values outside of main or any other function. This is not allowed. Global vars can be declared outside of main, and ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
linked-list × 49pset5 × 24
speller × 10
hash-table × 10
load × 5
pointers × 5
pset6 × 3
malloc × 3
cs50x × 2
c × 2
segmentation-fault × 2
array × 2
structs × 2
node × 2
typedef × 2
pset4 × 1
pset3 × 1
valgrind × 1
check × 1
trie × 1
dictionary × 1
memory-leak × 1
recursion × 1
printf × 1
file-io × 1