1#include23structNode{4Node*next;56Node(){nextNULL;}7Node(constNode 5 6 Node() { next = NULL;} 7 Node(const Node 9 } 10 }; 11 12 enum Error_code { 13 succeed, 14 overflow, 15 underflow 16 }; 17 18 class LinkQueue { 19 public: 20 LinkQueue();
1#include23structNode{4Node*next;56Node(){nextNULL;}7Node(constNode 5 6 Node() { next = NULL;} 7 Node(const Node 9 } 10 }; 11 12 enum Error_code { 13 succeed, 14 overflow, 15 underflow 16 }; 17 18 class LinkQueue { 19 public: 20 LinkQueue(); 21 LinkQueue(const LinkQueue 22 ~LinkQueue(); 23 24 LinkQueue 25 26 bool empty() const; 27 Error_code append(const Node 28 Error_code serve(); 29 Error_code retrieve(Node 30 int size() const; 31 32 protected: 33 Node * front, * rear; 34 }; 35 36 LinkQueue::LinkQueue() { 37 frOnt= rear = NULL; 38 } 39 40 LinkQueue::~LinkQueue() { 41 while (!empty()) 42 serve(); 43 } 44 45 LinkQueue::LinkQueue(const LinkQueue 47 Node * new_copy, * old_node=rhs.front; 48 if (old_node != NULL) { 49 new_frOnt=new_copy=new Node(*old_node); 50 while (old_node->next != NULL) { 51 old_node = old_node->next; 52 new_copy->next = new Node(*old_node); 53 new_copy = new_copy->next; 54 } 55 new_rear = new_copy; 56 } 57 58 frOnt= new_front; 59 rear = new_rear; 60 } 61 62 int LinkQueue::size() const { 63 Node * window = front; 64 int count = 0; 65 66 while(window != NULL) { 67 window = window->next; 68 count++; 69 } 70 71 return count; 72 } 73 74 Error_code LinkQueue::serve() { 75 if (frOnt== NULL) 76 return underflow; 77 78 Node * old_frOnt= front; 79 frOnt= front->next; 80 if (frOnt== NULL) 81 rear = NULL; 82 83 delete old_front; 84 85 return succeed; 86 } 87 88 bool LinkQueue::empty() const{ 89 if (frOnt== NULL) 90 return true; 91 return false; 92 } 93 94 Error_code LinkQueue::append(const Node 96 if (new_rear == NULL) 97 return overflow; 98 if (rear == NULL) 99 frOnt= rear = new_rear;100 else {101 rear->next = new_rear;102 rear = new_rear;103 }104 return succeed;105 }106 107 Error_code LinkQueue::retrieve(Node 110 item = *front;111 return succeed;112 }
LinkQueue class,布布扣,bubuko.com