?? chain.c
字號:
/*建立一個整數鏈表*/
#include <stdio.h>
#include <stdlib.h>
struct chain
{
int value;
struct chain *next;
};
struct chain *create()
{
struct chain *head, *tail, *p;
int x;
head = tail = NULL;
printf("Input data.\n");
while (scanf("%d",&x) == 1) /*如果輸入的是一個整型的數據,那么向下執行*/
{
p = (struct chain *)malloc (sizeof (struct chain));
/*首先為要新創建的表元p開辟一個內存空間*/
p->value = x;
p->next = NULL;
if(head == NULL)
head = tail = p;
else
/*tail為倒數第二個表元指針,tail->始終指向最后一個表元*/
tail = tail ->next;
tail ->next = p;
}
return head;
}
void main(){
struct chain *p,*q;
q = create();
while(q) {
printf("%d\n",q->value);
p = q->next;
free(q);
q = p;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -