显示正在访问未分配的内存
#include <iostream>
#include <cstring>
#include <queue>
using namespace std;
class Node {
public:
Node *next,*pre;
queue<int>num;
Node() {
next=pre=NULL;
while(!num.empty())
num.pop();
}
};
void del(Node *n) {
n->pre->next=n->next;
n->next->pre=n->pre;
}
void pushq(Node *a,Node *b) {
while(!b->num.empty()) {
a->num.push(b->num.front());
b->num.pop();
}
}
int main() {
int n,t,l=-1,num=0;
cin >> n;
Node *head,*tail,*m;
head = new Node;
tail=head;
head->next=NULL;
for(int i=1;i<=n;i++) {
cin >> t;
if(t==l) {
m->num.push(i);
continue;
}
m=new Node;
m->num.push(i);
m->pre=tail;
m->next=NULL;
tail->next=m;
l=t;
tail=m;
}
tail->next=NULL;
m=head->next;
while(head->next->next) {
m=head->next;
while(m!=NULL) {
cout << m->num.front() << ' ';
m->num.pop();
if(m->num.empty()) {
if(m->next!=NULL) {
cout << m->next->num.front() << ' ';
pushq(m->pre,m->next);
del(m->next);
}
m=m->next;
del(m->pre);
}
else
m=m->next;
}
cout << endl << 1 << endl;
}
return 0;
}