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

#include<stdio.h> #include<stdlib.h> #define MAXNUM 100 #define FALSE 0 #define TRUE 1 typedef int DataType; #define SPECIAL 2147483647 struct SeqList { DataType element[MAXNUM]; int n; }; typedef struct SeqList SeqList, *PSeqList;

PSeqList createNullList_seq( void ) /* 建立一个顺序表 */ { PSeqList palist; palist=(PSeqList)malloc(sizeof(struct SeqList)); if (palist!=NULL) palist ->n = 0; else printf("Out of space!!\n"); return palist; }; 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("not exist! \n"); return ( FALSE ); } for(q=palist->n - 1; q>=p; q--) palist->element[q+1] = palist->element[q]; palist->element[p] = x; palist->n = palist->n + 1; return ( TRUE ); } PSeqList delete_seq( PSeqList palist, int p ) /* 在palist所指顺序表中删除下标为p的元素 */ { int q; if ( p<0 || p>palist->n) { printf("not exist!\n "); return (FALSE); } for(q=p; q<palist->n-1; q++) palist->element[q] = palist->element[q+1]; palist->n = palist->n - 1; return ( palist ); }; DataType retrieve_seq( PSeqList palist, int p ) /* 求palist所指顺序表中第p个(即下标为p-1) 的元素的值 */ { if ( p>0 && p<=palist->n ) /* 存在下标为 p-1的元素 */ return ( palist->element[p-1] ); printf("Not exist.\n "); return SPECIAL; /* 返回一个顺序表中没有 的特殊元素值 */ }; void inputnsm(int* n,int* s,int* m) { printf("\n please input the values(<100) of n = "); scanf("%d",n); printf("\n please input the values of s = "); scanf("%d",s); printf("\n please input the values of m = "); scanf("%d",m); } void initlist(PSeqList jos_alist,int n) { int i,k; if (jos_alist==NULL) exit(1); for( i = 0; i < n; i++ ) { k=insert_seq( jos_alist, i, i+1); if (k==FALSE) exit(1); } } void josephus_seq( PSeqList palist, int s, int m) { int s1, i, w; s1 = s - 1; /* 找出列的元素 */ for(i = palist->n; i>0; i--) { s1 = ( s1 + m - 1 ) % i ; w = retrieve_seq(palist,s1); /* 求下标为s1的元素的值 */ printf("Out element %d \n",w); /* 元素出列 */ delete_seq(palist,s1); /* 删除出列的元素 */ getch(); } } main( ) {

PSeqList jos_alist; int n,s,m; inputnsm(&n,&s,&m); jos_alist=createNullList_seq( ); /* 创建空顺序表 */ initlist(jos_alist,n); josephus_seq(jos_alist,s,m); free(jos_alist);

getch(); }

这是我的程序

没有返回值a

搜索更多相关主题的帖子: 数据结构 palist SeqList define struct 
2004-09-16 14:03
samlee728
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2004-11-16
收藏
得分:0 

这是我用vc++ 写的刚刚写完 还没有优化,请大家帮帮忙怎么可以更好

我是个大菜鸟 呵呵 谢谢大家不吝赐教~~~~~

#include<stdio.h> #include<iostream.h> typedef struct poly { int data; struct poly *next; }polytype; polytype * create() { polytype *head,*p,*q; int m; int i=0; p=new polytype; if(!p) {head=NULL;return head;} cout<<"how many?\n"; cin>>m; cout<<"input the number~~~\n"; for(head=p;i<m;i++) { q=new polytype; cin>>q->data; p->next=q;p=q; } p->next=NULL; return head; } int getelem(polytype *La,int position) { polytype *p; int j=1,e; p=La->next; while(p&&j<position) {p=p->next;++j;} if(!p||j>position) {cout<<"error!!\n";return NULL;} e=p->data; return e; } polytype * list_insert(polytype *La,int i,int elem) { polytype *p,*head; p=La; head=p; int j=0; while(p&&j<i-1) {p=p->next;j++;} if(!p||j>i-1) {cout<<"error\n";return NULL;} polytype *n=new polytype; n->data=elem;n->next=p->next;p->next=n; return head; } polytype * list_delete(polytype *La,int i) { polytype *head=La; polytype *p=La; int j=0; while(p->next&&j<i-1) {p=p->next;++j;} if(!(p->next)||j>i-1) {cout<<"error\n";return NULL;} polytype *q=p->next;p->next=q->next; cout<<"the deleted data is"<<q->data<<"\n"; delete q; return head; } void print(polytype *La) { polytype *p; p=La->next; while(p) { cout<<" "<<p->data; p=p->next; } } main() { int p1,p2,p3,i; polytype *La=create(); print(La); cout<<"\nget which one?"; cin>>p1; cout<<getelem(La,p1); cout<<"insert element ? before ?'th\n"; cin>>i>>p2; polytype *Lb=list_insert(La,p2,i); print(Lb); cout<<"delete ?'th member\n"; cin>>p3; polytype *Lc=list_delete(La,p3); print(Lc); return 1; }

2004-11-16 23:15
快速回复:?WIN-TC 可以做数据结构吗? 不能吧?
数据加载中...
 
   



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

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