Write too lazy, too low-end.
After the code as far as possible in C + +, and so a little learning python that is also excellent.
Queue.h
1 #ifndef Queue_queue_h2 #defineQueue_queue_h3 4#include <stddef.h>5 6typedefintDataType;7 8typedefstruct_node {9 DataType data;Ten struct_node *Next; One A _node (DataType d) { -data =D; -Next =NULL; the } - _node () { -data =0; -Next =NULL; + } - }node; + A at //With Head Node - classQUEUE { - Public: - QUEUE (); -~QUEUE (); - in voidPush (DataType); - //return 1 = = OK to //return 0 = = ERROR + intPop (datatype*); - the Private: *NODE *head; $NODE *tail;Panax Notoginseng }; - the + #endif //Queue_queue_hQueue.cpp
1#include"queue.h"2 3 Queue::queue () {4Head =NewNODE (0);5Tail =head;6 }7 8 voidQUEUE::P ush (DataType data) {9NODE *tmp =NewNODE (data);TenTail->next =tmp; OneTail =tmp; ATMP =NULL; - } - the intQUEUE::P op (DataType *data) { - if(Head->next! =NULL) { -NODE *tmp = head->Next; -*data = tmp->data; +Head->next = tmp->Next; - Deletetmp; +TMP =NULL; A return 1; at}Else { - return 0; - } - } - -queue::~QUEUE () { inNODE *tmp =head; - while(TMP! =NULL) { to Deletetmp; +Head = head->Next; -TMP =head; the } *TMP =NULL; $Head =NULL;Panax NotoginsengTail =NULL; -}
Data Structure Note # queue