#include <stdio.h> #include <conio.h> #include <stdlib.h>//system (); This command needs to be used for this header file # include <ctype.h>//toupper to use # include <malloc.h>//header file used in memory management void main () {int i;struct Listentry{int number; Data domain struct ListEntry *next; Pointer to the next listentry node struct listentry *previous; Pointer to the previous ListEntry node}start,*node, *newone;start.next = NULL; Empty list start.previous = Null;node = &start; Start of the list for (i = 1; i <; i + = 2) {Node->next = (struct listentry*) malloc (sizeof (struct listentry)); node->next- >previous = Node;node = Node->next;node->number = I;node->next = NULL;} for (i = 2; I <=; i + = 2) {int found = 0;newone = (struct listentry*) malloc (sizeof (struct listentry)); Newone->numb ER = I;node = start.next;do{if (Node->number > Newone->number) {newone->next = node;newone->previous = node ->previous;node->previous->next = newone;node->previous = Newone;found = 1;} Else{node = Node->next;}} while ((Node->nexT) && (!found)); if (!found) if (Node->number > Newone->number) {newone->next = node;newone-> previous = Node->previous;node->previous->next = Newone;node->previous = Newone;} Else{newone->next = null;newone->previous = Node;node->next = Newone;}} node = start.next;do{printf ("%d", node->number); node = Node->next;} while (node); system ("Pause");}
This code is very classic, the 1-10 is not in book order into the two-way list, and again the orchestration, so that it finally output to 12345678910
C Classic 14-bidirectional list storage 1-10---Shinepans