我用数据结构解决jos_seq问题
程序如下
运行结果是 "No exist!"
我觉得是赋值没有赋上
请帮忙修改或给予好的赋值方法
谢谢先
#include<stdio.h> #include<stdlib.h> #define MAXNUM 100 #define FALSE 0 #define TRUE 1 #define SPECIAL 2147483647 typedef int DataType; struct SeqList { DataType element[MAXNUM]; int n; }; typedef struct SeqList *PSeqList; PSeqList creatNullList_seq(void); int insert_seq(PSeqList palist,DataType x,int p); int delete_seq(PSeqList palist,int p); DataType retrieve_seq(PSeqList palist,int p); int locate_seq(PSeqList palist,DataType x); DataType first_seq(PSeqList palist); DataType next_seq(PSeqList palist,DataType x); DataType previous_seq(PSeqList palist,DataType x); int isNullList_seq(PSeqList palist); PSeqList initlize(int n); void jos_seq(PSeqList palist ,int s,int m); void write_seq(PSeqList palist); main () { PSeqList palist ; int n,s,m; printf("Please input n:"); scanf("%d ",&n); /*printf("Please input s:"); scanf("%d ",&s); printf("Please input m:"); scanf("%d ",&m);*/ palist=initlize(n); write_seq(palist); /*jos_seq(palist ,s,m);*/ getch(); } PSeqList creatNullList_seq(void) { PSeqList palist; palist=(PSeqList)malloc(sizeof(struct SeqList)); if(palist!=NULL) { palist->n=0; return palist; } else { printf("Out of space"); return (NULL); } } int insert_seq(PSeqList palist,DataType x,int p) { int q; if(palist->n==MAXNUM) { printf("Overflow!\n"); return (FALSE); } if(p<0||p>(palist->n)) { printf("No exist!\n"); return (FALSE); } else { for (q=(palist->n);q>p;q--) { palist->element[q+1]=palist->element[q]; } palist->element[p]=x; palist->n=palist->n+1; } return(TRUE); } int delete_seq(PSeqList palist ,int p) { int q; if(p<0||p>palist->n) { printf("No exist!\n"); return (FALSE); } else { for(q=p;q<palist->n;q++) { palist->element[q]=palist->element[q-1]; } palist->n=palist->n-1; return (TRUE); } } int retrieve_seq(PSeqList palist,int p) { if(p<0||p>palist->n) { printf("No exist!\n"); return (SPECIAL); } else return (palist->element[p-1]); } int locate_seq(PSeqList palist ,DataType x) { int q; int p; for(q=1;q<palist->n;q++) { if(palist->element[q-1]==x) { p=q; break; } } return(p); } DataType first_seq(PSeqList palist ) { if(palist==NULL) return(SPECIAL); else return (palist->element[0]); } DataType next_seq(PSeqList palist ,int p) { if(p<0||p>=palist->n) { printf("No exist !\n"); return (SPECIAL); } else return (palist->element[p+1]); } DataType previous_seq(PSeqList palist ,int p) { if(p<=0||p>palist->n) { printf("No exist!\n"); return(SPECIAL); } else return(palist->element[p-1]); } int isNullList_seq(PSeqList palist ) { return (palist==NULL); } PSeqList initlize(int n) { int i; PSeqList palist; palist=creatNullList_seq(); for(i=0;i<n;i++) { insert_seq(palist ,i,i+1); } return (palist); } void write_seq(PSeqList palist) { int i; for(i=0;i<palist->n;i++) { printf("%d ",retrieve_seq(palist,i)); } } void jos_seq(PSeqList palist ,int s,int m) { int i; int j=palist->n; int s1; int w; s1=s-1; for(i=(palist->n);i>0;i--) { s1=(s+m-1)%i; w=retrieve_seq(palist ,s1); printf("%d is the %d out of the element",w,(j-i+1)); delete_seq(palist ,s1); } }