/ / 实现 队列 # include <stdio.h> # include <stdlib.h> struct node {int data; Node * pNext;}; Queue {struct node * head, Node * Rear;}; jewelry tool kit * Insert Queue (Queue * that , int x) {Node * istNode = (Node *) malloc (sizeof (Node)); istNode -> data = x; istNode -> pNext = NULL, if (it -> head == NULL) {it -> head = istNode, that -> rear = istNode; printf ("% d Insert! \ n" istNode -> data);} else {it -> rear -> pNext = istNode, that -> rear = istNode; printf (" Insert% d! \ n "istNode -> data);} return that;} * Delete Queue (Queue * who) {if (it -> head == NULL) {printf (" Error! ");} Node * from = NULL, if (it -> head == that -> rear) {='s that -> head, that -> head = NULL; than -> rear = NULL; printf ("Delete -% d! \ n "the -> data) free (from);} else {='s that -> head, that -> head = from -> pNext; printf (" Delete -% d! \ n ", the -> date ) free (from);} return that;} void PrintQueue (Queue * who) {if (it -> head == NULL) {printf jewelry tool kit ("NULL! \ n");} else {Node * = t_head that - > head, Node * it = t_rear -> rear, while (t_head! = t_rear) {printf ("% d", t_head -> data); t_head t_head = -> pNext;} printf ("% d", t_head - > date) printf ("\ n");}} int main () {* it = Queue (Queue *) malloc (sizeof (Queue)) that -> head = NULL; than -> rear = NULL; it = Insert (who, 1) = Insert it (which, 3) Insert that = (it, 4), which = Insert (which, 5) = Insert it (which, 3) = Insert it (which 1) Insert it = (it, 2); PrintQueue (that) it = Delete (to) = Delete it (that) it = Delete jewelry tool kit (to) = Delete it (that) jewelry tool kit it = Delete (which ) PrintQueue (which) system ("pause");}
Friday, September 20, 2013
/ / 实现 队列 # include
/ / 实现 队列 # include <stdio.h> # include <stdlib.h> struct node {int data; Node * pNext;}; Queue {struct node * head, Node * Rear;}; jewelry tool kit * Insert Queue (Queue * that , int x) {Node * istNode = (Node *) malloc (sizeof (Node)); istNode -> data = x; istNode -> pNext = NULL, if (it -> head == NULL) {it -> head = istNode, that -> rear = istNode; printf ("% d Insert! \ n" istNode -> data);} else {it -> rear -> pNext = istNode, that -> rear = istNode; printf (" Insert% d! \ n "istNode -> data);} return that;} * Delete Queue (Queue * who) {if (it -> head == NULL) {printf (" Error! ");} Node * from = NULL, if (it -> head == that -> rear) {='s that -> head, that -> head = NULL; than -> rear = NULL; printf ("Delete -% d! \ n "the -> data) free (from);} else {='s that -> head, that -> head = from -> pNext; printf (" Delete -% d! \ n ", the -> date ) free (from);} return that;} void PrintQueue (Queue * who) {if (it -> head == NULL) {printf jewelry tool kit ("NULL! \ n");} else {Node * = t_head that - > head, Node * it = t_rear -> rear, while (t_head! = t_rear) {printf ("% d", t_head -> data); t_head t_head = -> pNext;} printf ("% d", t_head - > date) printf ("\ n");}} int main () {* it = Queue (Queue *) malloc (sizeof (Queue)) that -> head = NULL; than -> rear = NULL; it = Insert (who, 1) = Insert it (which, 3) Insert that = (it, 4), which = Insert (which, 5) = Insert it (which, 3) = Insert it (which 1) Insert it = (it, 2); PrintQueue (that) it = Delete (to) = Delete it (that) it = Delete jewelry tool kit (to) = Delete it (that) jewelry tool kit it = Delete (which ) PrintQueue (which) system ("pause");}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment