链表1

来源:互联网 发布:手机网络发短信软件 编辑:程序博客网 时间:2024/05/20 22:02

问题及代码:

/* *Copyright (c)2015,大连东软信息学院  *All rights reserved.  *文件名称:get max.c  *作    者:陈振  *完成日期:2016年4月27日  *版 本 号: v1.0  *问题描述:链表1  *程序输入:  *程序输出:  */#include<stdio.h>#include<stdlib.h>typedef struct NODE{    int data;    struct NODE *next;}Node;void traverse(Node *h){    Node *p;    p=h;    while(p!=NULL){        printf("%d ",p->data);        p=p->next;    }    printf("\n");    return;}Node *createLinkList(int n){    Node *h=NULL,*last,*p;    int i,d;    for(i=0;i<n;i++){        scanf("%d",&d);        p=(Node *)malloc(sizeof(Node));        p->data=d;        p->next=NULL;        if(h==NULL)            h=p;        else            last->next=p;        last=p;    }    return h;}int main(){    Node *head;    head=createLinkList(2);    traverse(head);    return 0;}

运行结果:


0 0
原创粉丝点击