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

  • 相关阅读:
    怎样使android的view动画循环弹动
    QQ消息99+形成--第三方开源--BezierView
    自定义Toast的显示效果
    (转载)实现QQ侧滑边栏
    图片加载与缓存利器(自动缓存)--第三方开源-- Glide
    多层级Spinner列表选项实时更新树形层级(选择城市)
    android任意view爆炸效果--第三方开源--ExplosionField
    TextView字符串波浪式跳动--第三方开源---JumpingBeans
    简单Spinner
    【前端】JavaScript入门学习
  • 原文地址:https://www.cnblogs.com/summercloud/p/5529517.html
Copyright © 2011-2022 走看看