pzq25 2016-09-12 02:33 采纳率: 0%
浏览 2029

c语言,程序中函数没被调用。


#include<malloc.h>

#include<string.h>

#include<stdlib.h>

#define OK 0

#define Err_Memory -1

#define Err_InvalidParam -2

#define Err_Overflow -3

#define Err_IllegalPos -4

#define Err_NoResult -5

typedef char *ElemType ;

typedef struct node{

        ElemType data;

        struct node *next;

        }ListNode,*LinkList;

        typedef int Status;
Status InitList (LinkList L)
{
       if (!L) return Err_InvalidParam ;
       L->next=NULL;
       return OK;
}
Status CreateCollection (LinkList C)
{
       int count=1;
       ListNode *s,*p;
       ElemType e;
       if (InitList!=OK) return Err_NoResult ;
       p=C;
       while (1)
       {
             s=(ListNode *)malloc(sizeof(ListNode));
             if (!s) return Err_Memory;
             e=(ElemType)malloc(11*sizeof(char));
             if (!e) return Err_Memory;
             printf("请输入第%d个元素:",count++);
             gets(e);
             if (strcmp(e,"#")==0) break ;
             if (LocataList(e,C)==0)
             {
                                    if (InsertList(p,1,e)!=OK) return Err_NoResult ;
                                    p=p->next;
             }
       }
       return OK;
}
int LocateList (ElemType e,LinkList L)
{
    int i=1;
    ListNode *p;
    if (!L) return Err_InvalidParam ;
    p=L->next;
    while (p&&strcmp (p->data,e)!=0)
    {
          i++;
          p=p->next;
    }
    if (!p) return 0;
    return i;
}
Status InsertList (LinkList L,int i,ElemType e)
{
       ListNode *p,*s;
       int k=1;
       if (!L) return Err_InvalidParam ;
       p=L;
       while (k<i&&p)
       {
             k++;
             p=p->next;
       }
       if (k>i||!p) return Err_IllegalPos;
       s=(ListNode *)malloc(sizeof(ListNode));
       if (!s) return Err_Memory;
       s->data=e;
       s->next=p->next;
       p->next=s;
       return OK;
}
int main()
{
     LinkList A,B,C;
     ElemType s;
     A=(ListNode *)malloc(sizeof(ListNode));
     B=(ListNode *)malloc(sizeof(ListNode));
     C=(ListNode *)malloc(sizeof(ListNode));
     printf("请输入集合A的元素(输入#结束):\n");
     //scanf("%s",A);
     if (CreateCollection(A)!=OK) 
     { printf("集合A创建错误!"); getch();return ;}

图片说明

请问一下,为什么这里,CreateCollection 函数没有被调用呢?
初学数据结构。
补贴了Insert 和Locate 函数。

  • 写回答

4条回答 默认 最新

  • 逐梦如风 2016-09-12 02:38
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退