c语言线性表的逆转,数据结构(C语言)设有一个线性表E,将线性表逆置,要求逆线性表占? 爱问知识人...

输入数据,输出数据,及线性表的长度,

询问是否查找数据,若查找则由用户输入需查找的数据,显示此数据在线性表中的位置(第几个)

*/

#include

#include

#define NULL 0

#define LEN sizeof(struct Node)

struct Node

{

int num;

struct Node* next;

};

struct Node *createline();

void showline(struct Node *head);

int getlen(struct Node *head);

int selectline(struct Node *head,int data);

int main()

{

struct Node *head;

int selflag;

int len = 0;

head = createline();

if(head == NULL)

{

printf("create error

");

return 1;

}

showline(head);

printf("line's len is %d

",getlen(head));

printf("0 select,other not select

");

scanf("%d",&selflag);

if(selflag == 0)

{

printf("请输入要查找的数字:");

scanf("%d",&selflag);

len = selectline(head,selflag);

if(len num);

p1->next = NULL;

if(i == 0)

{

head = p1;

}

else

{

p2->next = p1;

}

p2 = p1;

}

return head;

}

void showline(struct Node *head)

{

struct Node *p1;

p1 = head;

while(p1)

{

printf("%d ",p1->num);

p1 = p1->next;

}

printf("

");

return ;

}

int getlen(struct Node *head)

{

int len = 0;

struct Node *p1;

p1 = head;

while(p1)

{

len = 1;

p1 = p1->next;

}

return len;

}

int selectline(struct Node *head,int data)

{

int len = 1;

int flag = 0;

struct Node *p1;

p1 = head;

while(p1)

{

if(p1->num == data)

{

flag = 1;

break;

}

len = 1;

p1=p1->next;

}

if(flag == 0)

{

len = -1;

}

return len;

}

另外,站长团上有产品团购,便宜有保证。

全部

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值