###### Eip_Nit_AC

2019-06-26 10:46 阅读 1.5k

# 数据结构的疑问：不存在从 "int" 转换到 "People" 的适当构造函数？

``````#include<stdio.h>
#include<iostream>
#define MaxWindow 30
#define MaxProc 1
#define error 0
using namespace std;
typedef struct People ElementType;

struct People
{
int T;
int P;
};

typedef int Position;
struct QNode
{
ElementType *Data;
Position Front, Rear;
int MaxSize;
};
typedef struct QNode *Queue;

Queue CreatQueue(int MaxSize)
{
Queue Q = (Queue)malloc(sizeof(struct QNode));
Q->Data = (ElementType *)malloc(MaxSize * sizeof(ElementType));
Q->Front = Q->Rear = 0;
Q->MaxSize = MaxSize;
return Q;
}

bool IsFull(Queue Q)
{
return((Q->Rear + 1) % Q->MaxSize == Q->Front);
}

bool AddQ(Queue Q, ElementType X)
{
if (IsFull(Q))
{
printf("队列满\n");
return false;
}
else
{
Q->Rear = (Q->Rear + 1) % Q->MaxSize;
Q->Data[Q->Rear] = X;
return true;
}
}

bool IsEmpty(Queue Q)
{
return(Q->Front == Q->Rear);
}

ElementType DeleteQ(Queue Q)
{
if (IsEmpty(Q))
{
printf("队列空\n");
return 0;
}
else
{
Q->Front = (Q->Front + 1) % Q->MaxSize;
return Q->Data[Q->Front];
}
}

void DestroyQueue(Queue Q)
{
free(Q);
}

double QueueingAtBank(Queue Q, int N)
{
struct People Next;
int k;
int TotalTime;
int CurrentTime;
int Window[MaxWindow];
int WaitTime;
int WinAvail;
int i, j;
scanf("%d", &k);

for (i = 0; i < k; i++)
Window[i] = 0;
TotalTime = 0;

while (!IsEmpty)
{
WinAvail = FindNextWindow(Window, k, &WaitTime);
CurrentTime += WaitTime;
Next = DeleteQ(Q);
if (CurrentTime >= Next.T)
TotalTime += (CurrentTime - Next.T);
else
{
WaitTime = Next.T - CurrentTime;
for (j = 0; j < k; j++)
{
Window[j] -= WaitTime;
if (Window[j] < 0)
Window[j] = 0;
}
CurrentTime = Next.T;
}
Window[WinAvail] = Next.P;
}
return((double)TotalTime / (double)N);
}

int FindNextWindow(int W[], int k, int *WaitTime)
{
int WinAvail;
int MinW = MaxProc + 1;
int i;
for (i = 0; i < k; i++)
if (W[i] < MinW)
{
MinW = W[i];
WinAvail = i;
}
*WaitTime = MinW;
for (i = 0; i < k; i++)
W[i] -= MinW;
return WinAvail;
}

int main()
{
int N;
Queue Q;
int i;
ElementType X;
scanf("%d", &N);
Q = CreatQueue(N);
for (i = 0; i < N; i++)
{
scanf("%d %d", &X.T, &X.P);
}
printf("Average waiting time = %.lf minute(s).\n", QueueingAtBank(Q, N));

DestroyQueue(Q);
return 0;
}
``````
``````1   IntelliSense:  不存在从 "int" 转换到 "People" 的适当构造函数
``````

• 点赞
• 写回答
• 关注问题
• 收藏
• 复制链接分享

#### 1条回答默认 最新

• 已采纳
我叫侯万楼 2019-06-26 19:47

建议编译一下代码

点赞 评论 复制链接分享