Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // main.cpp
- // Queue
- //
- // Created by 馮謙 on 2018/4/23.
- // Copyright © 2018年 馮謙. All rights reserved.
- //
- #include <iostream>
- #include <stdlib.h>
- #include "function.h"
- using namespace std;
- List_queue::List_queue(){
- head = NULL;
- tail = NULL;
- }
- List_queue::~List_queue(){
- ListNode *p;
- for (ListNode *i = head; i!=NULL;) {
- p = i;
- i = i->nextPtr;
- free(p);
- }
- }
- void List_queue::enqueue(const int &N){
- if (head == NULL) {
- head = (ListNode*)malloc(sizeof(ListNode));
- *head = ListNode(N);
- tail = head;
- } else {
- tail->nextPtr = (ListNode*)malloc(sizeof(ListNode));
- *(tail->nextPtr) = ListNode(N);
- tail->nextPtr->prevPtr = tail;
- tail = tail->nextPtr;
- }
- }
- void List_queue::dequeue(){
- ListNode *tem;
- if (head != NULL) {
- tem = head;
- head = head->nextPtr;
- free(tem);
- }
- }
- void List_queue::print(){
- ListNode *i;
- if (head!=NULL) {
- for (i = head; i->nextPtr!=NULL; i = i->nextPtr) {
- cout << i->data << " ";
- }
- cout << tail->data;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement