| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 698 人关注过本帖
标题:利用尾插法建立的单链表为什么元素输出时还是逆序的 求大神指点
取消只看楼主 加入收藏
winner1995
Rank: 2
等 级:论坛游民
帖 子:64
专家分:41
注 册:2015-10-11
结帖率:88.89%
收藏
 问题点数:0 回复次数:3 
利用尾插法建立的单链表为什么元素输出时还是逆序的 求大神指点
#include<iostream.h>
#include<stdlib.h>
int n;
typedef struct node{
    int data;
    struct node *next;
}node, * list;
void createlist(list *L)
{int i;
    *L=(list)malloc(sizeof(node));
    (*L)->next=NULL;
    list p;
    cout<<"enter data's number:";
cin>>n;
    cout<<"enter data:";
for(i=0;i<n;i++)
{
    p=(list)malloc(sizeof(node));
    cin>>p->data;
    p->next=(*L)->next;
    (*L)->next=p;
}
}
void outputlist(list *L)
{
cout<<"your list is:"<<endl;
for(int i=0;i<n;i++)
{cout<<(*L)->next->data<<"\t";
*L=(*L)->next;
}
}
int main()
{list L1;
createlist(&L1);
outputlist(&L1);
return 0;
}
搜索更多相关主题的帖子: include number 元素 
2015-10-26 17:03
winner1995
Rank: 2
等 级:论坛游民
帖 子:64
专家分:41
注 册:2015-10-11
收藏
得分:0 
回复 楼主 winner1995今天晚上才猛的看明白 这个可以了
#include<iostream.h>
#include<stdlib.h>
int n;
typedef struct node{
    int data;
    struct node *next;
}node, * list;
void createlist(list *L)
{int i;
    *L=(list)malloc(sizeof(node));
    (*L)->next=NULL;
    list p,r;
    r=*L;
    cout<<"enter data's number:";
cin>>n;
    cout<<"enter data:";
for(i=0;i<n;i++)
{
    p=(list)malloc(sizeof(node));
    cin>>p->data;
    r->next=p;
    r=p;
}
}
void outputlist(list *L)
{
cout<<"your list is:"<<endl;
for(int i=0;i<n;i++)
{cout<<(*L)->next->data<<"\t";
*L=(*L)->next;
}
}
int main()
{list L1;
createlist(&L1);
outputlist(&L1);
return 0;
}

唯望君安~
2015-11-04 22:40
winner1995
Rank: 2
等 级:论坛游民
帖 子:64
专家分:41
注 册:2015-10-11
收藏
得分:0 
回复 3楼 TonyDeng
严蔚敏,吴伟民编的 数据结构
或许是我能力有限吧  不能怪书  哈哈

唯望君安~
2015-11-13 21:10
winner1995
Rank: 2
等 级:论坛游民
帖 子:64
专家分:41
注 册:2015-10-11
收藏
得分:0 
回复 9楼 TonyDeng
恩恩  受教了thank you

唯望君安~
2015-11-15 23:47
快速回复:利用尾插法建立的单链表为什么元素输出时还是逆序的 求大神指点
数据加载中...
 
   



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

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