博文
约瑟夫环--别人的(2006-04-03 19:11:00)
摘要:
/*要求:用循环链表实现约瑟夫环程序,给定犯人编号分别是3,1,7,2,4,8,4。
*报数初值由用户输入,打印输出队列。
*令m=20作为测试数值,正确的出列顺序为6,1,4,7,2,3,5
*ch.nan@163.com 整理于2005.12.01 */
/*******************************************************************************/
#include <stdio.h>
#include <malloc.h>
#define N 7 //定义N=7,表示有7个链表单元
#define OVERFLOW 0
#define OK 1
typedef struct LNode{ //定义链表结构
int password;
int order;
 ......
约瑟夫环(2006-04-03 18:32:00)
摘要:#include<stdio.h>#include<stdlib.h>#define TRUE 1#define FALSE 0#define OK 1#define ERROR 0#define INFESIBLE -1#define OVERFLOW -2typedef int status;typedef int BOOL;typedef int ElemType;typedef struct Node{ ElemType pasword; int number; struct Node *next;}LNode,*linklist;
linklist Initlinklist(void){ linklist p; ElemType psw; p=(linklist)malloc(sizeof(LNode)); if(!p) { printf("can't init linklist!\n"); exit(0); } printf("please enter the first pasword:\n"); scanf("%d",&psw); p->number=1; p->next=NULL; p->pasword=psw; return p;}
void Insertlinklist(linklist p,ElemType a[],int n){ int i; linklist q,h; h=p; for(i=1;i<n+1;i++) { q=(linklist)malloc(sizeof(LNode)); if(!q) { printf("can't malloc room\n"); system("pause"); exit(0); } q->......
