linkedLists Flashcards

1
Q

How do you create the Node for linkedlist?

A

struct Node {

struct Node *next;

int val;

};

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you initialize the linkedlist?

A

struct Node * first = NULL;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you code a function to add an item to the linked list?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How would you code searching a linked list

A

struct node * search_list(struct node *list, int key){

while(list !=NULL && list->val != n)

list = list->next;

return list;

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How would you code deleting a node from a linked list?

A

struct node * delete_from_list(struct node * list, int n){

struct node *cur, prev;

for(cur = list, prev = NULL; curr != NULL && cur->value != n;prev=curr, curr = curr->next){

if(curr == NULL)

return list;

if(prev == NULL)

list = list->next;

else

prev->next = curr->next;

free(cur);

return list;

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you free the memory from an entire linked list?

A

void *free_list(struct node *list)

{

struct node *next;

while(list != NULL){

next = list->next;

free(list);

list = next;

}

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly