征服c語言第一天

從今天開始,將每天在簡書里面記錄著我學習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;

}

}
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容