zoukankan      html  css  js  c++  java
  • 队列

    //C++ 对列的基本预算
    
    #include <iostream>
    using namespace std;
    
    typedef struct node
    {
    	int data;
    	struct node *next;
    }node;
    
    
    typedef struct quene
    {
    	node *head;
    	node *end;
    }quene;
    
    
    /*
    创建一个空链式队列
    */
    int Create(struct quene *s)
    {
    	s->head = (node*)malloc(sizeof(node));//申请头节点
    	if (s->head == NULL)
    	{
    		cout<<"Initial Failure"<<endl;
    		return (0);
    	}
    	else
    	{
    		 s->end = s->head;
    		 s->head->next = NULL;
    		 return(1);
    	}
    
    }
    /*
    清空队列
    */
    int DestoryQuene(struct quene *s)
    {
    	while(s->head!=NULL)
    	{
    		s->end = s->head->next;
    		free(s->head);
    		s->head = s->end;
    	}
    	return (1);
    }
    
    /*
    队列的入队操作
    */
    quene* InsertQuene(struct quene *s,int x)
    //x为要插入的元素
    {
    	struct node *p;
    	p = (node*)malloc(sizeof(node)); //为插入的值分配一个内存
    	p->data =x;
    	p->next =NULL;
    
    	s->end->next =p;
    	s->end = p;
    	
    	return s;
    }
    
    
    /*
    队列的出队操作
    */
    quene* DeleteQuene(struct quene *s)
    //x为要删除的元素
    {
    	node *p;
    	p = s->head->next;
    	s->head = p;
    	free(p);
    	return (s);
    }
    
    /*
    求队列的长度
    */
    int LengthQuene(struct quene *s)
    {
    	int i = 0
    	node *p;
    	p = s->head->next;
    	while(p != NULL)
    	{
    		i++;
    		p= p->next;
    	}
    	return (i);
    }
    
  • 相关阅读:
    Use HTTPS instead of HTTP
    Disable SSLv3
    JIRA Installation
    排序算法之简单选择排序
    排序算法之冒泡排序
    三本优秀的Python教程
    ubuntu*set*up
    程序员的十层楼(转载)
    drools spring config的问题
    MySQL Performance Tuning
  • 原文地址:https://www.cnblogs.com/CBDoctor/p/2625829.html
Copyright © 2011-2022 走看看