c改c++,不能运行了!!!跪求为什么!
#include<iostream.h>
using namespace std;
#define error 0
#define N
3
#define OVERFLOE -1
#include<stdlib.h>
#include "math.h"
#include<stdio.h>
#include "conio.h"
FILE *fp;
int m=0;int z=0,v=0,d=0;
typedef struct PCB
{
int
id;
struct PCB *next;
int
yxs;
int
cput;
int
time;
int
status; /*0表wait,1表run,2表finish */
} PCB,*queueptr;
typedef struct
{ queueptr
front;
queueptr
rear ;
} linkqueue;
int initqueue(linkqueue *q)
{
q->front=q->rear=(queueptr)malloc(sizeof(PCB));
if(!q->front)exit(OVERFLOW);
q->front->next=NULL;
printf("used initqueue %d time\
",++d);
return 1;
}
int enqueue (linkqueue *q,int e1,int e2,int e3,int e4,int e5)
{
PCB *p;
p=(queueptr)malloc(sizeof(PCB));
/**/
if(!p)exit(OVERFLOE);
{p->id=e1 ;
p->yxs=e2;
p->cput=e3;
p->time=e4;
p->status=e5;
p->next=NULL;
q->rear->next=p;
q->rear=p;
/*printf("used enqueue %d time:\
",++m); */cout<<"调用了enqueue函数:"<<++m<<"次"<<endl;
return 2;
}
void sort(int c[ ], int n)
/* 选择排序*/
{
int i,j,k,t;
for(i=0;i<n-1;i++)
{ k=i;
for(j=i+1;j<n;j++)
if(c[j]>c[k])k=j;
if(k!=i)
{ t=c[i];c[i]=c[k];c[k]=t;}
}
/* printf("used sort %d time:\
",++v); */ cout<<"调用了sort函数:"<<++v<<"次"<<endl;
}
void insert(PCB *p, linkqueue *Q )
/*按顺序插入*p节点*/
{
PCB
*ptr ;
ptr=Q->front;
while(p->yxs<ptr->next->yxs&&ptr->next!=NULL) /*从第二个节点开始比较插入*/
ptr=ptr->next;
if(p->yxs>=ptr->next->yxs&&ptr->next!=NULL)
{ p->next=ptr->next;
ptr->next=p; }
else
{p->next=NULL;
/*p.yxs<ptr->next->yxs&&ptr->next==NULL*/
ptr->next=p;
Q->rear=Q->rear->next;
}
/* printf("used insert %d times:\
",++z);*/cout<<"调用了insert函数:"<<++z<<"次"<<endl;
}
答案:以下程序在g++下编译通过(仅编译,没链接),修改了#include <iostream>,和struct定义新类型的部分
楼上,不需要向量容器的。
#include<iostream>
using namespace std;
#define error 0
#define N 3
#define OVERFLOE -1
#include<stdlib.h>
#include "math.h"
#include<stdio.h>
#include "conio.h"
FILE *fp;
int m=0;int z=0,v=0,d=0;
struct PCB
{
int id;
PCB *next;
int yxs;
int cput;
int time;
int status; /*0表wait,1表run,2表finish */
} ;
typedef PCB* queueptr;
struct linkqueue
{ queueptr front;
queueptr rear ;
};
int initqueue(linkqueue *q)
{
q->front=q->rear=(queueptr)malloc(sizeof(PCB));
if(!q->front)exit(OVERFLOW);
q->front->next=NULL;
printf("used initqueue %d time\
",++d);
return 1;
}
int enqueue (linkqueue *q,int e1,int e2,int e3,int e4,int e5)
{ PCB *p;
p=(queueptr)malloc(sizeof(PCB)); /**/
if(!p)exit(OVERFLOE);
{p->id=e1 ;
p->yxs=e2;
p->cput=e3;
p->time=e4;
p->status=e5;
p->next=NULL;
q->rear->next=p;
q->rear=p;
/*printf("used enqueue %d time:\
",++m); */cout<<"调用了enqueue函数:"<<++m<<"次"<<endl;
return 2;
}
}
void sort(int c[ ], int n) /* 选择排序*/
{
int i,j,k,t;
for(i=0;i<n-1;i++)
{ k=i;
for(j=i+1;j<n;j++)
if(c[j]>c[k])k=j;
if(k!=i)
{ t=c[i];c[i]=c[k];c[k]=t;}
}
/* printf("used sort %d time:\
",++v); */ cout<<"调用了sort函数:"<<++v<<"次"<<endl;
}
void insert(PCB *p, linkqueue *Q ) /*按顺序插入*p节点*/
{
PCB *ptr ;
ptr=Q->front;
while(p->yxs<ptr->next->yxs&&ptr->next!=NULL) /*从第二个节点开始比较插入*/
ptr=ptr->next;
if(p->yxs>=ptr->next->yxs&&ptr->next!=NULL)
{ p->next=ptr->next;
ptr->next=p; }
else
{p->next=NULL; /*p.yxs<ptr->next->yxs&&ptr->next==NULL*/
ptr->next=p;
Q->rear=Q->rear->next;
}
/* printf("used insert %d times:\
",++z);*/cout<<"调用了insert函数:"<<++z<<"次"<<endl;
}...你胡搞什么
上一个:Visual C++是什么,哪里有的下?
下一个:c++ 类库中list中的函数有哪些