Skip to main content
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 ...
Cliff B's user avatar
  • 69k
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 (...
Blauelf's user avatar
  • 21k
1 vote

Kinda confused with what needs memory allocated in pset5

well, no where to start, first see the hash tablenode* hashtable[ALPHA], is an array of pointers to node, are pointers we will use to store our words according to their index hash, to equal hash index ...
MARS's user avatar
  • 5,179
1 vote
Accepted

Trouble Interpreting Linked List Sample Code - PSET5

first, I wanna make it clear that there is a difference between the address of a pointer and the address stored in a pointer (aka the address that the pointer points to). pointers are special type ...
kzidane's user avatar
  • 17.7k
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 -> ...
C--'s user avatar
  • 306
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 ...
Cliff B's user avatar
  • 69k
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 ...
DinoCoderSaurus's user avatar
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.
curiouskiwi's user avatar
  • 18.7k
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 ...
Blauelf's user avatar
  • 21k
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 ...
Cliff B's user avatar
  • 69k
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] ...
Blauelf's user avatar
  • 21k
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 ...
Cliff B's user avatar
  • 69k
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 ...
Blauelf's user avatar
  • 21k
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 ...
Cliff B's user avatar
  • 69k
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?...
Cliff B's user avatar
  • 69k
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) { ...
Blauelf's user avatar
  • 21k
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) { ...
Blauelf's user avatar
  • 21k
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 ...
obesman's user avatar
  • 1,139
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 ...
Cliff B's user avatar
  • 69k

Only top scored, non community-wiki answers of a minimum length are eligible