suxue / cplusplus-practices-2011

Automatically exported from code.google.com/p/cplusplus-practices-2011
0 stars 0 forks source link

帮同学问一下 打印数值的时候怎么崩溃 #13

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
#include<stdio.h>
typedef struct node{
    int data;
    struct node *next;
}ListNode,*ListNodePtr;

void Creat_List(ListNodePtr L,int n){
    ListNodePtr p,q;
    int i;
    int a;

    q=(ListNodePtr)malloc(sizeof(ListNode));
    q->data=n;
    q->next=NULL;

    for(i=1;i<=n;i++){
        p=(ListNodePtr)malloc(sizeof(ListNode));
        printf("请输入第%d个元素:\n",i);
        scanf("%d",&a);
        p->data=a;
        p->next=q->next;
        q->next=p;
    }
    L=q;
}

void Print_List(ListNodePtr L){
    ListNodePtr p=L->next;
    int i=1;
    for(i;i<=5;i++){
        printf("第%d个数据为:%d\n",i,p->data);
        p=p->next; 
    }
}

void main(){
    int n=5;
    ListNodePtr L;
    Creat_List(L,n);
    Print_List(L);
}

Original issue reported on code.google.com by kkerF...@gmail.com on 10 Oct 2011 at 2:11

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
L=q 改成 *L=*q

Original comment by Cdegre...@gmail.com on 15 Oct 2011 at 3:43