Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. //
  2. // main.cpp
  3. // Queue
  4. //
  5. // Created by 馮謙 on 2018/4/23.
  6. // Copyright © 2018年 馮謙. All rights reserved.
  7. //
  8.  
  9. #include <iostream>
  10. #include <stdlib.h>
  11. #include "function.h"
  12. using namespace std;
  13.  
  14. List_queue::List_queue(){
  15. head = NULL;
  16. tail = NULL;
  17. }
  18.  
  19. List_queue::~List_queue(){
  20. ListNode *p;
  21. for (ListNode *i = head; i!=NULL;) {
  22. p = i;
  23. i = i->nextPtr;
  24. free(p);
  25. }
  26. }
  27.  
  28. void List_queue::enqueue(const int &N){
  29. if (head == NULL) {
  30. head = (ListNode*)malloc(sizeof(ListNode));
  31. *head = ListNode(N);
  32. tail = head;
  33. } else {
  34. tail->nextPtr = (ListNode*)malloc(sizeof(ListNode));
  35. *(tail->nextPtr) = ListNode(N);
  36. tail->nextPtr->prevPtr = tail;
  37. tail = tail->nextPtr;
  38. }
  39.  
  40. }
  41.  
  42. void List_queue::dequeue(){
  43. ListNode *tem;
  44. if (head != NULL) {
  45. tem = head;
  46. head = head->nextPtr;
  47. free(tem);
  48. }
  49. }
  50.  
  51. void List_queue::print(){
  52. ListNode *i;
  53. if (head!=NULL) {
  54. for (i = head; i->nextPtr!=NULL; i = i->nextPtr) {
  55. cout << i->data << " ";
  56. }
  57. cout << tail->data;
  58. }
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement