從今天開始,將每天在簡書里面記錄著我學習c語言的一些心得,與感悟。
實際上,大學里面老師只是起到了領進門的作用,我們不能因為老師水,就放棄了c語言,c語言確實是一種比較難理解但好做的語言,也有入門到放棄的無心之談。
C語言中的鏈表操作
1.單向鏈表
單項鏈表的數據結構分為數據域 和指針域
struct node{
int data;//數據域
struct node *next;//指針域
}
2.創建動態鏈表
#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;
}
}