论坛: 编程破解 标题: 数据线性表问题? 复制本贴地址    
作者: shen [shen]    论坛用户   登录
我刚学了数据线性表,老师让用C把插入,删除,求表长,建表全写出来
我建表是用的
LList v={5,{1,2,3,4,5}];
可老师不让这的建说用完就不行了,我不知道怎么建新的表
请问应该如何建?

地主 发表时间: 11/15 12:36

回复: lwei889 [lwei889]   论坛用户   登录
不清楚你的老师要求是什么?也不太清楚你到底是怎么创建的而不合要求,(希望你在发贴时,把问题说的明白??)我知道数据表分顺序存储和连接存储,
下面这个例子是连接存储方式:
#define LEN sizeof(struct list)
#include <stdlib.h>
typedef struct list link;
struct list {
char name[10];
char sex[5];
int age;
struct list *next;
};
main()
{link *head,*temp,*tail,*p;
int i;
clrscr();
temp=(struct list *)malloc(LEN);
head=temp;
tail=head;
for(i=0;;i++){
  printf("\nplease input your name:");
    scanf("%s",temp->name);
  if(temp->name[0]!='#')
  {
    printf("\nplease input your sex:");
    scanf("%s",temp->sex);
    printf("\please input your age:");
    scanf("%d",&temp->age);
    temp->next=NULL;
    tail=temp;
    }
  else
    {
    free(temp);
    tail->next=NULL;
    break;
    }
  temp->next=(link *)malloc(LEN);
  temp=temp->next;
  }

p=head;
while(p!=NULL)
  {printf("\nthe information as follow:");
    printf("\n\t%s:\t%s\t%d\t",p->name,p->sex,p->age);
    p=p->next;
  }
  getch();
}
我是初学者,如果有误导的地方,请大家给予指正!!!!!


B1层 发表时间: 11/17 17:24

回复: ceo_8008 [ceo_8008]   论坛用户   登录
简单地说要用指针去开拓空间,然后再使用

你那样当然不行

关于这个建议你先去看书,不然说了你也看得很吃力的

书上有很详细的建立的程序(不会没书吧,呵呵~~~~~)



B2层 发表时间: 11/17 22:15

回复: jilian [jilian]   论坛用户   登录
好像是先生成一个表结点,然后已建好的表的头指针(头插法),或尾指针指向它(尾插法),我是生手~

B3层 发表时间: 11/18 12:39

论坛: 编程破解

20CN网络安全小组版权所有
Copyright © 2000-2010 20CN Security Group. All Rights Reserved.
论坛程序编写:NetDemon

粤ICP备05087286号