?? queue.cpp
字號:
// queue.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
typedef int content;
typedef struct _node
{
content stcon;
struct _node* pnext;
} node;
typedef struct _queue
{
node *pfirst;
node *plast;
int nlenth;
} queue;
int Init_queue( queue *pQu)
{
pQu->pfirst = NULL;
pQu->plast = NULL;
pQu->nlenth = 0;
return 1;
}
int Get_queue(queue *pQu)
{
node * pexplore = pQu->pfirst;
if ( pQu->pfirst == NULL )
return 0;
for ( ;pexplore != NULL ;)
{
printf("%d " , pexplore->stcon);
pexplore = pexplore->pnext;
}
return 1;
}
int Out_queue(queue *pQu)
{
node * del = pQu->pfirst;
if ( pQu->nlenth == 0)
return 0;
pQu->pfirst = pQu->pfirst->pnext;
pQu->nlenth--;
delete (del);
return 1;
}
int In_queue(queue *pQu,content stin)
{
if ( pQu->nlenth == 0)
{
pQu->plast = new (node);
pQu->pfirst = pQu->plast;
}
else
{
pQu->plast->pnext = new (node );
pQu->plast = pQu->plast->pnext;
}
pQu->plast->stcon = stin;
pQu->plast->pnext = NULL;
pQu->nlenth++;
return 1;
}
int _tmain(int argc, _TCHAR* argv[])
{
int i = 0;
int j = 0;
content nn = 1;
content get = 0;
queue Qu;
Init_queue(&Qu);
if (0 == Get_queue(&Qu))
printf( "empty queue! \n");
if (0 == Out_queue(&Qu))
printf( " queue is empty! \n");
In_queue(&Qu,nn); printf( "%d \n" ,Qu.nlenth);
nn = 2;
In_queue(&Qu,nn);printf( "%d \n" ,Qu.nlenth);
nn = 3;
Out_queue(&Qu);printf( "%d \n" ,Qu.nlenth);
In_queue(&Qu,nn);printf( "%d \n" ,Qu.nlenth);
Out_queue(&Qu);printf( "%d \n" ,Qu.nlenth);
Out_queue(&Qu);printf( "%d \n" ,Qu.nlenth);
if ( 0 == Get_queue(&Qu))
printf( " queue is empty! \n");
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -