这个为啥无法运行呢
秦帅 2019-06-19 03:58:14 #include<iostream>
#include<graphics.h>
using namespace std;
struct Node
{
int x;
int y;
struct Node * next;
int flag;
};
typedef struct Node node;
node * head_1 = NULL;
node * head_2 = NULL;
node * input(node *);
void draw(node *);
int main(void)
{
head_1=input(head_1);
head_2=input(head_2);
initgraph(640,480);
setcolor(GREEN);
draw(head_1);
draw(head_2);
getch();
closegraph();
return 0;
}
node * input(node *)
{
cout << "输入第1个点" << endl;
char c;
node * p = NULL;
head_1 = (node *)malloc(sizeof(node));
cin >> head_1->x;
cin >> head_1->y;
head_1->flag = 0;
head_1->next = NULL;
cout << "是否继续 y or n " << endl;
cin >> c;
if (c == 'y')
{
do
{
node *a = head_1;
p = (node *)malloc(sizeof(node));
cout << "输入顶点坐标\n";
cin >> p->x >> p->y;
p->flag = 0;
p->next = NULL;
while (a->next != NULL)
{
a = a->next;
}
a->next = p;
cout << "是否继续 y or n " << endl;
cin >> c;
} while (c == 'y');
}
p->next = head_1;
return head_1;
}
void draw(node * head)
{
node * p = head;
node * q = head->next;
while (1)
{
line(p->x, p->y, q->x, q->y);
p = p->next;
q = q->next;
if (q == head->next)
{
break;
}
}
}