请问问题出在哪里?
#include<cstdio>
#include<cstdlib>
#include<map>
using namespace std;
int n,a[200005];
map<int,bool>pd;
struct Node
{
int data;
Node *next;
};
Node *p,*head,*r;
int main(){
head=new Node;
r=head;
scanf("%d",&n);
int g=n;
for(int i=1;i<=n;i++){
p=new Node;
p->data=i;
p->next=NULL;
r->next=p;
r=p;
scanf("%d",&a[i]);
pd[i]=1;
}
p=head->next;
int q=a[1];
printf("%d ",a[1]);
if(q)q=0;
else q=1;
pd[1]=0;
while((a[p->data]!=q)&&(p->next!=NULL))p=p->next;
while(g){
while(p->next!=NULL){
if(a[p->data]==q){
if(pd[p->data]){
pd[p->data]=0;
g--;
printf("%d ",p->data);
if(q)q=0;
else q=1;
while((a[p->data]!=q)&&(p->next!=NULL))p=p->next;
}
else{
while(!pd[p->data]&&p->data!=n)p=p->next;
}
}
}
printf("\n");
p=head->next;
}
return 0;
}