Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct node node;
- struct node {
- node *next;
- node *prev;
- int key;
- };
- void addTail(node *list, int key);
- void list_show(node *list);
- int main() {
- node *list = (node*) malloc(sizeof(node)); //old node *new_list_node() but structure name is list
- list->prev = NULL; //old node *new_list_node()
- list->next = NULL; //old node *new_list_node()
- list->key = NULL; //old node *new_list_node()
- addTail(list, 10);
- addTail(list, 15);
- addTail(list, 20);
- list_show(list);
- }
- void addTail(node *list, int key) {
- if (list->key == NULL) {
- list->key = key;
- } else {
- while(list->next != NULL) {
- list = list->next;
- }
- node *new_node = (node*) malloc(sizeof(node));
- new_node->next = NULL;
- new_node->prev = list;
- new_node->key = key;
- list->next = new_node;
- }
- }
- void list_show(node *list) {
- while (list != NULL) {
- printf("%d ", list->key);
- list = list->next;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement