(1) User input m,n value, starting from 1 to n sequential number of cycles, each number to M output this value, until the full output. Write the C program.

Source: Internet
Author: User

Using the circular chain list, with the take-over operation. (VS2010)

#include <stdio.h>
#include <stdlib.h>
#include "stdafx.h"
#include <iostream>
typedef struct node{
int data;
Node* Next;
}node;

void Creatlist (node*& head, node*& tail, int n) {
if (n<1) {
Head = tail = NULL;
Return
}
Head = new node ();
Head->data = 1;
Head->next = NULL;
node* p = head;
for (int i=2; i<n+1; i++)
{
P->next =new node ();
p = p->next;
P->data = i;
P->next = NULL;
}
tail = p;
Tail next = head;
}

void Print (node*& head) {
node* p = head;
while (P && p->next! = head) {
printf ("%d", p->data);
p = p->next;
}
if (p) {
printf ("%d\n", p->data);

}
}

void Countprint (node*& head, node*& tail, int m) {
node* pre = tail;
node* cur = head;
int cnt = m;
while (cur && cur->next! = cur) {
if (cnt! = 1) {
cnt--;
Pre = cur;
Cur = cur->next;
}else{
printf ("%d", cur->data);
Pre->next =cur->next;
Delete cur;
Cur = pre->next;
CNT = m;
}
}
if (cur) {
printf ("%d", cur->data);
Delete cur;
head = Tail =null;
}
}

int main () {
node* Head;
node* tail;
int m;
int n;
scanf_s ("%d", &n);
scanf_s ("%d", &m);
Creatlist (head, tail, n);
Print (head);
Countprint (HEAD,TAIL,M);
System ("pause");
return 0;
}

(1) User input m,n value, starting from 1 to n sequential number of cycles, each number to M output this value, until the full output. Write the C program.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.