## Introduction

I’ve introduced the Queue structure in previous post. In contiguous storage, queues were significantly harder to manipulate than were stacks, because it was necessary to treat straight-line storage as though it were arranged in a circle, and the extreme cases of full queues and empty queues caused difficulties. As a result, I introduce you the linked queue in this post.

### Implementation

Based on the previous definition of Queue, I’ll give the definition of LinkedQueue.(LinkedQueue.hpp)

1 | template <class Queue_entry> |

We need only keep two pointers, **front** and **rear**, which will point respectively, to the beginning and the end of the queue.

#### LinkedQueue()

*preposition*: None.*postposition*: The Queue is initialized to be empty.

1 | template <class Queue_entry> |

#### empty()

*preposition*: None.*postposition*: Return **true** if the Queue is empty, otherwise return **false**

1 | template <class Queue_entry> |

#### append(**const** Queue_entry &item)

*preposition*: None.*postposition*: Add item to the rear of the Queue and return a code of Success or return a code of OverFlow if dynamic memory is exhausted.

1 | template <class Queue_entry> |

#### serve()

*preposition*: None.*postposition*: The front of the Queue is removed. If the Queue is empty, return an Error_code of UnderFlow.

1 | template <class Queue_entry> |

#### retrieve(Queue_entry &item)

*preposition*: None.*postposition*:If the Queue is not empty, the front of the Queue has been recorded as item, and return Success. Otherwise an Error_code of UnderFlow is returned.

1 | template <class Queue_entry> |

#### ~LinkedQueue()

*preposition*: None.*postposition*: Release the queue itself.

1 | template <class Queue_entry> |

#### LinkedQueue(**const** LinkedQueue &original)

*preposition*: None.*postposition*: The Queue is initialized as a copy of Queue original.

1 | template <class Queue_entry> |

#### operator=(**const** LinkedQueue< Queue_entry > &original)

*preposition*: Node.*postposition*: The Queue is reset as a copy of Queue original.

1 | template <class Queue_entry> |

#### operator == (**const** LinkedQueue< Queue_entry > &original)

*preposition*: None.*postposition*: Return **true** if the Queue is the same as the Queue original, otherwise return **false**.

1 | template <class Queue_entry> |

#### clear()

*preposition*: None.*postposition*: Clear all the items in the queue.

1 | template <class Queue_entry> |

#### size()

*preposition*: None.*postposition*: Return the number of entries in the Queue.

1 | template <class Queue_entry> |

#### serve_and_retrieve(Queue_entry &item)

*preposition*: None.*postposition*: Return UnderFlow if the Queue is empty. Otherwise remove and copy the item at the front of the Queue to item and return Success.

1 | template <class Queue_entry> |

Hereto, I’ve show you the Queue by using linked storage. This dynamic way to store elements enables us to handle data more conveviently and handy. Hope this post will be helpful to you. Thank you so much!