Escolar Documentos
Profissional Documentos
Cultura Documentos
Linked Lists
Stack
Queue
1 Data Structures
2 Linked Lists
Background
C implementation
3 Stack
Background
C implementation
4 Queue
Background
C implementation
Topics
1 Data Structures
2 Linked Lists
Background
C implementation
3 Stack
Background
C implementation
4 Queue
Background
C implementation
Topics
1 Data Structures
2 Linked Lists
Background
C implementation
3 Stack
Background
C implementation
4 Queue
Background
C implementation
Topics
1 Data Structures
2 Linked Lists
Background
C implementation
3 Stack
Background
C implementation
4 Queue
Background
C implementation
Linked lists
Linked lists
Linked design
Topics
1 Data Structures
2 Linked Lists
Background
C implementation
3 Stack
Background
C implementation
4 Queue
Background
C implementation
/* Assume that we can only insert at the "right" end of the list. */
void insert_into_list(Linked_List *list, int x) {
Node *runner = list->head;
Node *node = (Node *) malloc (sizeof(Node));
if (node == NULL) {
printf("Sorry, the computer can no longer allocate memory.\n");
} else {
node->data = x;
node->link=NULL;
if (is_list_empty(list)) {
list->head = node;
} else {
while (runner->link != NULL) {
runner = runner->link;
}
runner->link = node;
}
}
}
main() {
Linked_List list;
initialize_list(&list);
insert_into_list(&list, 1);
insert_into_list(&list, 3);
insert_into_list(&list, 5);
insert_into_list(&list, 7);
print_list(&list);
destroy_list(&list);
}
Topics
1 Data Structures
2 Linked Lists
Background
C implementation
3 Stack
Background
C implementation
4 Queue
Background
C implementation
Topics
1 Data Structures
2 Linked Lists
Background
C implementation
3 Stack
Background
C implementation
4 Queue
Background
C implementation
Stack
Topics
1 Data Structures
2 Linked Lists
Background
C implementation
3 Stack
Background
C implementation
4 Queue
Background
C implementation
main() {
Stack stack;
initialize_stack(&stack);
push(&stack, -3);
push(&stack, -5);
push(&stack, 14);
push(&stack, 2);
print_stack(&stack);
pop(&stack);
print_stack(&stack);
pop(&stack);
print_stack(&stack);
pop(&stack);
print_stack(&stack);
pop(&stack);
print_stack(&stack);
pop(&stack);
}
Topics
1 Data Structures
2 Linked Lists
Background
C implementation
3 Stack
Background
C implementation
4 Queue
Background
C implementation
Topics
1 Data Structures
2 Linked Lists
Background
C implementation
3 Stack
Background
C implementation
4 Queue
Background
C implementation
Queue
Queue
Queue
Topics
1 Data Structures
2 Linked Lists
Background
C implementation
3 Stack
Background
C implementation
4 Queue
Background
C implementation
END OF LESSON 9