无聊中,有C语言写了个(matlab应该更加容易,但为了假装在工作--反正老板是是假装付给我工资的...)
#include "stdafx.h"
#include "stdio.h"
#include "string.h"
#include <malloc.h>
struct strque {
char a[5];
struct strque *pNext;
} ;
void main(void)
{
int i, m, n;
strque *p, *h, *s;
n = 10;
m = 8;
if((h = (strque *)malloc(sizeof(strque)))==NULL)
{
printf("不能分配内存空间!");
return;
}
strcpy(h->a, "1");
h->pNext = NULL;
p = h;
// 构建循环链表
for(i = 1; i<n; i++)
{
char str[5];
sprintf(str, "%-5d", i+1);
if((s = (strque *)malloc(sizeof(strque)))==NULL)
{
printf("不能分配内存空间!");
return;
}
p->pNext = s;
strcpy(s->a, str);
s->pNext = NULL;
p = s;
}
p->pNext = h;
s = h;
p = s->pNext;
char chars[5];
i = 1;
while(s->pNext != p->pNext)
{
i++;
if(i == m)
{
i = 1;
strcpy(chars, p->a);
printf("%s\n", chars);
s->pNext = p->pNext;
p = s->pNext;
}
s = s->pNext;
p = p->pNext;
}
strcpy(chars, p->a);
printf("%s\n", chars);
}
[此贴子已经被作者于2006-6-26 17:11:56编辑过]