| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 429 人关注过本帖
标题:请教关于链表的指针问题,
只看楼主 加入收藏
czl1
Rank: 1
等 级:新手上路
帖 子:39
专家分:0
注 册:2006-8-17
收藏
 问题点数:0 回复次数:3 
请教关于链表的指针问题,

先将26个字母输入链表,再从链表中取出,取出指针怎么指向?
#include "stdio.h"
#include "malloc.h"
struct node
{
int date;
struct node *next;
};

main()
{
struct node *p;
char c;
for(c=122;c>=98;c--)
{
p = (struct node *)malloc(sizeof(struct node));
printf("%d\n",sizeof(struct node));
p->date=c;
p=p->next;

}
p = (struct node *)malloc(sizeof(struct node));
p->date='a';
p->next=NULL;
for(c=122;c>=97;c--)
{
printf("%c",p->date);
p--;
}

}

搜索更多相关主题的帖子: 链表 指针 
2007-01-23 11:46
tyc611
Rank: 1
等 级:新手上路
帖 子:83
专家分:0
注 册:2007-1-21
收藏
得分:0 

#include <stdio.h>
#include <malloc.h>

struct node
{
int date;
struct node *next;
};

int main()
{
struct node *pHead, *pCur;
char c;

pHead = (struct node *)malloc(sizeof(struct node));
pCur = pHead;
for(c = 'z'; c >= 'b'; c--)
{
printf("%d\n",sizeof(struct node));
pCur->date = c;
pCur->next = (struct node *)malloc(sizeof(struct node));
pCur = pCur->next;
}
pCur->date = 'a';
pCur->next = NULL;

for(pCur = pHead; pCur != NULL; pCur = pCur->next)
printf("%c",pCur->date);

return 0;
}

给你改了一下代码,自己琢磨一下,看来你根本就没理解链表,在纸上画画吧

另外,
1. 对于库头文件,应该是尖括号形式,如<stdio.h>,只有自己定义的头文件才是双引号形式,如"myheader.h"
2. main函数的返回值类型是int



2007-01-23 12:07
czl1
Rank: 1
等 级:新手上路
帖 子:39
专家分:0
注 册:2006-8-17
收藏
得分:0 
感谢tyc611!
我又学到的一招。
2007-01-23 13:57
czl1
Rank: 1
等 级:新手上路
帖 子:39
专家分:0
注 册:2006-8-17
收藏
得分:0 
请问,可以让链表逆序输出吗?
2007-01-23 14:08
快速回复:请教关于链表的指针问题,
数据加载中...
 
   



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

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