📄 queue.c
字号:
/* * queue.cc * Copyright (C) 1998,1999 SAKAI Katsuya * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */#include <stdio.h> // #include <iostream.h>#include "queue.h"inline u_long EventQueue::NextTime(){ return (item==0) ? (~0UL) : queue[1]->Time;}Event *EventQueue::store(Event *aEvent){ if(item>=Max) return aEvent; register u_long j, k; item++; j = item; queue[item]=aEvent; while(j>1) { k = (int)j/2; if(queue[j]->Time < queue[k]->Time) { queue[0] = queue[j]; queue[j] = queue[k]; queue[k] = queue[0]; } else break; j = k; } return NULL;}Event *EventQueue::retrieve(){ if(item==0) return NULL; Event *rtn; rtn = queue[1]; queue[1] = queue[item]; item--; register u_long j=1, k; while(j*2 <= item) { if(j*2+1 <= item ) { queue[0] = min(queue[j], queue[j*2], queue[j*2+1]); if(queue[0]==queue[j]) break; else if(queue[0]==queue[j*2]) k=j*2; else k=j*2+1; queue[0] = queue[k]; queue[k] = queue[j]; queue[j] = queue[0]; j = k; } else { if( queue[j]->Time < queue[j*2]->Time ) break; queue[0] = queue[j]; queue[j] = queue[j*2]; queue[j*2] = queue[0]; j = j*2; } } return rtn;}Event *EventQueue::min(Event *a, Event *b, Event *c){ return ( a->Time < b->Time ) ? (( a->Time < c->Time )? a : c) : (( b->Time < c->Time )? b : c);}/* { if( a->Time < b->Time ) if( a->Time < c->Time ) return a; else return c; else if( b->Time < c->Time ) return b; else return c; }*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -