Home > Back-end >  Death squads problem. I want to know if the subject to count from which a soldier, a platoon leader
Death squads problem. I want to know if the subject to count from which a soldier, a platoon leader

Time:09-17

#include
#include
Struct node {
int data;
Struct node * next;
};
Struct node * Createlist (int n) {/* create a circular linked list */
Struct node * head, tail, * p;
int i;
The head=(struct node *) malloc (sizeof (struct node));
The head - & gt; data=https://bbs.csdn.net/topics/1;/* head range of values of the node is not null */
The head - & gt; Next=NULL;
Tail=head;
For (I=2; i<=n; I++) {
P=(struct node *) malloc (sizeof (struct node));
P - & gt; data=https://bbs.csdn.net/topics/i;
P - & gt; Next=NULL;
Tail - & gt; Next=p;
Tail=p;
}
Tail - & gt; Next=head;/* the tail pointer to head node, constitute a circular linked list */
return head;
};
Int main () {
Int n, k;
Head, struct node * * p, * t;
While (the scanf (" % d ", & amp; N)!=EOF& & n!=0) {
The head=Createlist (n);
For (p=head, k=1; P=p - & gt; Next, k++) {/* k to mark a scalar, used to record pointer through junction points */
If (k % 5==0) {/* when to take more than 5 k equals 0, or sending a platoon either delete the current node */
If (p - & gt; data=https://bbs.csdn.net/topics/=1) {
Printf (" % d \ n ", k/5);
break;
}
The else {
T=head;
While (t - & gt; Next!=p)/* to find the nodes of the previous */
T=t - & gt; next;
T - & gt; Next=p - & gt; next;/* to delete the current node */
}
}
}
}
return 0;

CodePudding user response:

With the serial number tag
  • Related