zoukankan      html  css  js  c++  java
  • 队列

    // 队列操作类.cpp : 定义控制台应用程序的入口点。

    //

    #include "stdafx.h"

    #include<iostream>

    using namespace std;

    struct list

    {

    int data;

    list *next;

    };

    class Queue

    {

    public:

                    Queue()

                    {

                                    ptrf = ptrb = 0;

                    }

    void enqueue(int x);//入队函数

    int dequeue();//出队函数

    private:

    list *ptrf;//队首指针

    list *ptrb;//队尾指针

    };

    void Queue ::enqueue(int x)

    {

    list *newnode = new list;//动态内存分配

                    newnode->data = x;

                    newnode->next = NULL;

    if (ptrb == NULL )//队空时入队情况

                                    ptrf = ptrb = newnode;

    else //队非空时入队

                    {

                                    ptrb->next = newnode;

                                    ptrb = newnode;

                    }

    }

    int Queue ::dequeue()

    {

    list *tmp;

    int value;

                    value = ptrf->data;

                    tmp = ptrf;

                    ptrf = ptrf->next;

    delete tmp;

    return value;

    }

    int main()

    {

    Queue A;

    int arr[] = { 2,3,4,5,6 };

                    cout << "入队:" ;

    for (int i = 0; i < 5; i++)

                    {

                                    cout << arr[i] << " ";

                                    A.enqueue(arr[i]);

                    }

                    cout << endl << "出队:";

    for (int i = 0; i < 5; i++)

                                    cout << A.dequeue() << " ";

                    cout << endl;

                    system( "pause");   

    return 0;

    }

    图像 1

  • 相关阅读:
    Security and Cryptography in Python
    Security and Cryptography in Python
    Security and Cryptography in Python
    Security and Cryptography in Python
    Security and Cryptography in Python
    Security and Cryptography in Python
    Security and Cryptography in Python
    微信小程序TodoList
    C语言88案例-找出数列中的最大值和最小值
    C语言88案例-使用指针的指针输出字符串
  • 原文地址:https://www.cnblogs.com/summercloud/p/5529517.html
Copyright © 2011-2022 走看看