在线性表中插入1到10十个数字C语言完整程序

如题所述

第1个回答  2012-03-04
#include "stdio.h"
#include "stdlib.h"
typedef struct node
{
int data;
struct node *next;
}NODE;
NODE *init_list(void)
{
NODE *head;
head=(NODE *)malloc(sizeof(NODE));
return head;
}
void insert_data(int data,NODE *head)
{
NODE *r,*s;
r=head;
while(r->next!=NULL)
r=r->next;
s=init_list();
s->data=data;
r->next=s;
r=s;
r->next=NULL;
r->next=NULL;
}
void print_data(NODE *head)
{
for(head=head->next;head!=NULL;head=head->next)
printf("%d ",head->data);
}
int main(void)
{
NODE *head;
int i;
head=init_list();
for(i=1;i<=10;i++)
insert_data(i,head);
print_data(head);
printf("\n");
return 0;
}

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网