| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 645 人关注过本帖
标题:请教数据结构问题
取消只看楼主 加入收藏
bcomer
Rank: 1
等 级:新手上路
帖 子:113
专家分:0
注 册:2004-9-13
收藏
 问题点数:0 回复次数:1 
请教数据结构问题

我用数据结构解决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); } }

搜索更多相关主题的帖子: 数据结构 
2004-09-21 10:13
bcomer
Rank: 1
等 级:新手上路
帖 子:113
专家分:0
注 册:2004-9-13
收藏
得分:0 

上面是我的调试结构

以下是我的jos_seq结构

#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); 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); 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 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); } }

2004-09-21 10:17
快速回复:请教数据结构问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020520 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved