| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1201 人关注过本帖
标题:有大佬知道为什么do while循环里重复定义结构指针是可以的呢,还有给结构指 ...
取消只看楼主 加入收藏
铁甲
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2020-10-21
结帖率:80%
收藏
已结贴  问题点数:20 回复次数:1 
有大佬知道为什么do while循环里重复定义结构指针是可以的呢,还有给结构指正赋NUll是怎么回事,有啥好处
#include<stdio.h>
#include<stdlib.h>
typedef struct _node{
int value;
struct _node *next;
}Node;
int main(int argc,char const *argv[]){
Node *head=NULL;
int number;
do {
scanf("%d",&number);
if(number!=-1){
Node *p=(Node *)malloc(sizeof(Node));
p->value=number;
p->next=NULL;
Node *last=head;
if(last){
while(last->next){
last=last->next
}
last->next=p;
}
else {
head=p;
}
}while(number!=-1);

return 0;
}
搜索更多相关主题的帖子: next Node NUll while 结构 
2020-11-11 09:51
铁甲
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2020-10-21
收藏
得分:0 

#include<stdio.h>
#include<stdlib.h>
typedef struct _node{
    int value;
    struct _node *next;
}Node;
int main(int argc,char const *argv[]){
    Node *head=NULL;
    int number;
    do {
        scanf("%d",&number);
        if(number!=-1){
            Node *p=(Node *)malloc(sizeof(Node));
            p->value=number;
            p->next=NULL;
            Node *last=head;
            if(last){
                while(last->next){
                last=last->next;
            }
                last->next=p;
            }
            else {
                head=p;
            }
        }
    }while(number!=-1);

return 0;
}
2020-11-11 09:56
快速回复:有大佬知道为什么do while循环里重复定义结构指针是可以的呢,还有给结 ...
数据加载中...
 
   



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

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