VC++6.0程序设计系列-队列的实现

2025-11-02 12:25:51

1、新建工程01

VC++6.0程序设计系列-队列的实现

2、新建工程02

VC++6.0程序设计系列-队列的实现

3、新建工程03

VC++6.0程序设计系列-队列的实现

4、新建工程04

VC++6.0程序设计系列-队列的实现

5、新建工程05

VC++6.0程序设计系列-队列的实现

6、新建工程06

VC++6.0程序设计系列-队列的实现

7、新建工程07

VC++6.0程序设计系列-队列的实现

8、添加代码

#include <iostream>using namespace std ;struct Node{    int data ;    Node * next ;    Node():data(0),next(NULL){}    Node(int d):next(NULL){data=d ;}};class Queue{private :    Node *head ;    Node *tail ;public :    Queue(){        head = NULL ;        tail = head ;    }        int Pop() {        if(head == NULL) throw "error" ;        Node* p = head ;        if(head->next == NULL)tail = NULL ;        head = head->next ;        int res = p->data ;        delete p ;        return res ;    }    void Push(int d) {        Node * p = new Node(d) ;        if(head == NULL) {            head = p ;            tail = p ;        }        else {            tail->next = p ;            tail = p ;        }    }    bool Empty(){        return head == NULL ;    }};int main(){    int i = 0 ;    int ds [] = {1,2,3,4,5,6} ;    Queue q ;    int n = sizeof(ds)/sizeof(int) ;    for(i = 0 ; i < n ;i++)    {        q.Push(ds[i]) ;    }    for(i = 0 ; i < n ;i++){        cout<<q.Pop()<<" ";    }    cout<<endl;    return  0 ;}

VC++6.0程序设计系列-队列的实现

9、调试运行

VC++6.0程序设计系列-队列的实现

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢