Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- using namespace std;
- class node{
- public:
- int data;
- node*next;
- };
- class queue{
- public:
- node*head;
- queue(){
- head = new node;
- head->next = NULL;
- }
- void enqueue(int i);
- void dequeue();
- };
- void queue::enqueue(int i){
- node*x = new node;
- x->next = NULL;
- x->data = i;
- if (head->next == NULL)
- {
- head->next = x;
- return;
- }
- node*p = new node;
- p->next = head;
- while (p->next != NULL){
- p = p->next;
- }
- p->next = x;
- }
- void queue::dequeue(){
- node*current = head, *pre = NULL;
- if (current->next != NULL){
- current = current->next;
- cout << current->data << endl;
- pre = current->next;
- current->next = NULL;
- head->next = pre;
- delete current;
- }
- else{
- cout << "Empty" << endl;
- }
- }
- int main()
- {
- queue s1;
- for (int i = 0; i < 11; i++)
- s1.enqueue(i);
- for (int i = 0; i < 12; i++)
- s1.dequeue();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement