從今天開始,將每天在簡書里面記錄著我學(xué)習(xí)c語言的一些心得,與感悟。
實(shí)際上,大學(xué)里面老師只是起到了領(lǐng)進(jìn)門的作用,我們不能因?yàn)槔蠋熕头艞壛薱語言,c語言確實(shí)是一種比較難理解但好做的語言,也有入門到放棄的無心之談。
C語言中的鏈表操作
1.單向鏈表
單項鏈表的數(shù)據(jù)結(jié)構(gòu)分為數(shù)據(jù)域 和指針域
struct node{
int data;//數(shù)據(jù)域
struct node *next;//指針域
}
2.創(chuàng)建動態(tài)鏈表
#include<stdio.h>
#include<malloc.h>
#define LEN sizeof(struct node)
struct node{
int data;
struct node *next;
};
int n;
struct node *create()
{ struct node *head,*p1,*p2;
n=0;
head=NULL;
p1=p2=(struct node *)malloc(LEN);
scanf("%d",&p1->data);
while(p1->data!=-1)
{ n=n+1;
if(n==1) head=p1;
else p2->next=p1;
p2=p1;
}
}