Home > Back-end >  A group: Thu OJ - Mr ZUMA SIGSEGV mistakes
A group: Thu OJ - Mr ZUMA SIGSEGV mistakes

Time:09-21

PA1 zuma programming assignments, tsinghua data structure before 15 are AC, behind 5 case suggests that the runtime error (11) - the SIGSEGV, try to find out the problem but always can't find the problem? Have a headache
 
#include
#include
# define MAXNUM 10000
Char beads [MAXNUM];//record the initial list of node information

Typedef struct node {
Char col.
Pre struct node * and * suc;
} the node;

Int the Insert (node * head, int k, char c, int _size);//in _size scale of chain table, insert the new node to k position,
//the node color for c, returns the list size
Int Del_scol (node * head, node * trail, int _size);//repeated traversal, delete 3 + continuous nodes of the same color, return list size

Int main ()
{
Node * head=(*) malloc (sizeof (node));//initialization list
Node * trail=(*) malloc (sizeof (node));
The head - & gt; Suc=trail;
The head - & gt; The pre=NULL;
Trail - & gt; The pre=head;
Trail - & gt; Suc=NULL;
The head - & gt; Col='-';
Trail - & gt; Col='\ 0';//puts () function

Gets (beads);
Int _size=0;//the list size
for(int i=0; Beads [I]; I++)//update the initial list size
_size=Insert (head, I, beads, [I] _size);

int n;//number of executions
The scanf (" % d ", & amp; N);

If (n==0)
If (_size==0)
Printf (" % c \ n ", the head - & gt; Col);
The else {
_size=Del_scol (head and trail, _size);
If (_size==0)
Printf (" % c \ n ", the head - & gt; Col);
The else
For (the node * p=head - & gt; Suc; P!=trail; P=p - & gt; Suc)
Printf (" % c ", p - & gt; Col);
}
The else {
Int k [n].//insert position
Char co [n].//the color of the new node
for(int i=0; iThe scanf (" % d % c ", & amp; [I], k & amp; Co [I]);
Char RCD [n] [_size + n];//record the remaining nodes after each operation information
for(int i=0; iNode * p;//refers to the character to enter
Int h;//RCD [] in the ith row first h column
_size=Insert (head, k [I], co [I], _size);
_size=Del_scol (head and trail, _size);
If (_size==0) {
RCD [I] [0]='-';
RCD [I] [1]='\ 0';
}
The else
For (p=head - & gt; Suc h=0; p; P=p - & gt; Suc h++)
RCD [I] [h]=p - & gt; Col.
}
for(int i=0; iPuts (RCD [I]);
}

return 0;
}

Int the Insert (node * head, int k, char c, int _size) {
Node * ne=(*) malloc (sizeof (node));//create a new node
Ne - & gt; Col=c;
Node * p=head;

If (k> _size)//k cross-border processing
K=_size;
Else if (k<0)
K=0;

for(int i=0; iP=p - & gt; Suc;

P - & gt; Suc - & gt; The pre=ne;
Ne - & gt; Suc=p - & gt; Suc;
P - & gt; Suc=ne;
Ne - & gt; The pre=p;
Return + + _size;
}

Int Del_scol (node * head, node * trail, int _size) {
Ph node * and * pt;//the same color area the pointer to the head and tail pointer
Int num=0;//the same color node number
Ph=head - & gt; Suc;
While (ph& & Ph - & gt; Suc& & Ph - & gt; Suc - & gt; Suc) {
If (ph - & gt; Col==ph - & gt; Suc - & gt; Col & amp; & Ph - & gt; Col==ph - & gt; Suc - & gt; Suc - & gt; Col) {//for the same color at least 3 times in a
Num=3;
Pt=ph - & gt; Suc - & gt; Suc;
While (pt - & gt; Col==pt - & gt; Suc - & gt; Col) {//points to the same color area end node
Pt=pt - & gt; Suc;
num++;
}
Ph - & gt; The pre - & gt; Suc=pt - & gt; Suc;
Pt - & gt; Suc - & gt; The pre=ph - & gt; The pre.
_size=num -
Ph=head - & gt; Suc;
}
The else
Ph=ph - & gt; Suc;//back to the precursor of the deleted node
}
Return _size;
}
  • Related