I have nothing to worry about recently and don't want to waste my youth. I will start to read the previous notes and books and make some records.
The queue is implemented in C language as follows:
# Include
# Include
Typedef struct Node {int data; struct Node * next;} * Node; typedef struct Queue {int size; struct Node * first; struct Node * end;} * Queue; # define MAX_SIZE 10 Queue CreatEmptyQueue () {Queue queue = NULL; queue = (Queue) malloc (sizeof (struct Queue); if (queue = NULL) {printf ("malloc mem error! \ N "); exit (-1);} queue-> size = 0; queue-> first = NULL; queue-> end = NULL; return queue ;} int isEmpty (Queue queue) {return (queue-> size <= 0);} int isFull (Queue queue) {return (queue-> size> = MAX_SIZE );} int QueueIn (Queue queue, int data) {assert (queue! = NULL); Node p = NULL; if (isFull (queue) {printf ("in queue error! The Queue is full \ n "); return;} p = (Node) malloc (sizeof (struct Node); if (p = NULL) {printf ("malloc mem error! \ N "); return-1;} p-> data = data; p-> next = NULL; if (isEmpty (queue) = 1) {queue-> first = p; queue-> end = p;} else {queue-> end-> next = p; queue-> end = p ;} queue-> size = queue-> size + 1; return 0;} int QueueOut (Queue queue, int * data) {assert (queue! = NULL & data! = NULL); Node p; if (isEmpty (queue) = 1) {printf ("Queue is empty! \ N "); return-1;} p = queue-> first; * data = p-> data; queue-> first = queue-> first-> next; queue-> size = queue-> size-1; if (isEmpty (queue) = 1) {queue-> end = NULL; queue-> first = NULL ;} free (p); return 0;} void printQueue (Queue queue) {assert (queue! = NULL); printf ("queue size id: % d \ n", queue-> size); Node p; p = queue-> first; while (p! = NULL) {printf ("% d", p-> data); p = p-> next;} printf ("\ n ");} void destoryQueue (Queue queue) {assert (queue! = NULL); Node p, q; if (isEmpty (queue )! = 1) {q = p = queue-> first; while (p! = NULL) {queue-> size = queue-> size-1; printf ("have % d node \ n", queue-> size); q = p-> next; free (p); p = q ;}} queue-> first = NULL; queue-> end = NULL; free (queue); queue = NULL ;} int main (int argc, char * argv []) {Queue queue = NULL; int data; int I; int ret; printf ("Enter main! \ N "); queue = CreatEmptyQueue (); ret = QueueOut (queue, & data); if (ret = 0) {printf (" read success data is: % d \ n ", data);} else {printf (" The queue is empty, not havs data \ n ");} for (I = 0; I
There should be many defects in the code, but the code is compiled by gcc on ubuntu.
If you have any questions, please point them out. Thank you very much.