| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 536 人关注过本帖
标题:函数调用
只看楼主 加入收藏
苍海孤鸿
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2011-3-27
收藏
 问题点数:0 回复次数:0 
函数调用
#define list_size 15
#define increment 5
#define ok    1
#define overflow -1
#define error -2
#include "stdlib.h"
#include "stdio.h"
typedef struct{ int *elem;
        int length;
        int listsize;}sqlist;
/**********************************************/
int initlist(sqlist *L)
{ L->elem=(int *)malloc(list_size*sizeof(int));
  if(!L->elem) exit(overflow);
  L->length=0;
  L->listsize=list_size;
  return ok;  }
/**********************************************/
int listinsert( sqlist *L,  int i,  int e )
{ int *p,*q,*newbase;
if(i<1||i>L->length+1) return error;
if(L->length>=L->listsize)
{newbase=(int *)realloc(L->elem,(L->listsize+increment)*sizeof(int));
 if(!newbase)exit(overflow);
 L->listsize+=increment;}
 q=&(L->elem[i-1]);
 for(p=&(L->elem[L->length-1]);p>=q;--p) *(p+1)=*p;   *q=e;   ++L->length;
 return ok;}
/***********************************************/
int listDelete( sqlist *L,  int i )
{
 int *p,*q,e;
if(i<1||i>L->length+1) return error;
p=&(L->elem[i-1]);
e=*p;
printf("*********************\n");
printf("%d",e);
q=L->elem+L->length-1;
for(++p;p<=q;++p)
    *(p-1)=*p;
--L->length;
return ok;
}
/***********************************************/
int Locateelem(sqlist *L,int e,int(*compare)(int,int))
{
    int i,*p;
i=1;
p=L->elem;
while(i<=L->length&&!(*compare)(*p++,e))
++i;
if(i<=L->length) return i;
else return 0;
}
/***********************************************/
void printlist(sqlist *L)
{int i;
printf("\n*********************");
printf("\nThe element of the sqlist are:\n");
for(i=0;i<L->length;i++)
printf("%d    ",L->elem[i]);
printf("\n*********************\n");
return;
}
/***********************************************/
main(   )
{   int i,j,e;
  sqlist L1;
  initlist(&L1);
  printf("\n Please insert the length of the sqlist:\n");
  scanf("%d",&L1.length);
  printf("\n Please insert the element of the sqlist:\n");
  for(i=0; i<L1.length; i++)
  scanf( "%d", &L1.elem[ i ]);
  printlist(&L1);
  printf("\nPlease insert the value of j ane e :\n");
  scanf("%d%d",&j,&e);
  listinsert(&L1, j, e);
  printlist(&L1);
printf("\nPlease listDelete the value of j ane e :\n");
  scanf("%d",&j);
  listDelete(&L1, j);
  printlist(&L1);
  Locateelem(&L1,e,int(*compare)(&L1,e));
 }
中的 Locateelem含输调用错误在哪;
搜索更多相关主题的帖子: return 
2011-05-12 08:49
快速回复:函数调用
数据加载中...
 
   



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

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