JMeter之BeanShell內建方法的使用
阿新 • • 發佈:2022-05-06
queue.h
#ifndef _QUEUE_H #define _QUEUE_H #include "all.h" #define LEN 3 //定義一個描述佇列中每一個結點的結構體 typedef struct queuenode { Player *pArr; int MaxLen; int front; int rear; }queue_node; //建立空佇列 int empty_queue(queue_node **ppQueue,int len); //入隊 int in_queue(queue_node *pQueue,Player Data);//顯示隊內容 int show_queue(queue_node *pQueue); //銷燬隊 int destruction_queue(queue_node **ppQueue); #endif
queue.c
#include "../include/queue.h" //建立空佇列 int empty_queue(queue_node **ppQueue,int len) { if(NULL == ppQueue) { return ERROR; } //分配空間 *ppQueue = (queue_node *)malloc(sizeof(queue_node)); if(NULL == *ppQueue) { printf("malloc error"); return ERROR; } memset(*ppQueue,0,sizeof(queue_node)); //為佇列分配空間 (*ppQueue)->pArr = (Player *)malloc(sizeof(Player) * len); if(NULL == (*ppQueue)->pArr) { printf("malloc error");return ERROR; } memset((*ppQueue)->pArr,0,sizeof(Player)); //初始化 (*ppQueue)->MaxLen = len; (*ppQueue)->front = 0; (*ppQueue)->rear = 0; return OK; } //入隊 int in_queue(queue_node *pQueue,Player Data) { if(NULL == pQueue) { return ERROR; } if(pQueue->front == (pQueue->rear + 1) % pQueue->MaxLen) { pQueue->front = (pQueue->front + 1) % pQueue->MaxLen; } pQueue->rear = (pQueue->rear + 1) % pQueue->MaxLen; pQueue->pArr[pQueue->rear] = Data; return OK; } //顯示隊內容 int show_queue(queue_node *pQueue) { int i; if(NULL == pQueue) { return ERROR; } printw("Information of recent retired players is as follows:\n"); for(i = 0; pQueue->rear != (pQueue->front + i) % pQueue->MaxLen; i++) { printw("************************\n"); printw("Name:\t%s\n",pQueue->pArr[(pQueue->front + i + 1) % pQueue->MaxLen].name); printw("ID:\t%s\n",pQueue->pArr[(pQueue->front + i + 1) % pQueue->MaxLen].id); printw("Pos:\t%s\n",pQueue->pArr[(pQueue->front + i + 1) % pQueue->MaxLen].position); printw("Team\t%s\n",pQueue->pArr[(pQueue->front + i + 1) % pQueue->MaxLen].team); printw("************************\n"); } return OK; } //銷燬隊 int destruction_queue(queue_node **ppQueue) { if(NULL == ppQueue) { return ERROR; } free((*ppQueue)->pArr); (*ppQueue)->pArr = NULL; free(*ppQueue); *ppQueue = NULL; return OK; }