數(shù)據(jù)結(jié)構(gòu):是計算機存儲海渊,組織數(shù)據(jù)的方式痊班。數(shù)據(jù)結(jié)構(gòu)是指相互之間存在一種或多種特定關(guān)系的數(shù)據(jù)元素的集合净捅。通常情況下,精心選擇的數(shù)據(jù)結(jié)構(gòu)可以帶來更高的運行或者存儲效率辩块。數(shù)據(jù)結(jié)構(gòu)往往同高效的檢索算法和索引技術(shù)有關(guān)
1.創(chuàng)建個鏈表:
#include <stdio.h>
#include <stdlib.h>
//#define NULL 0
structNode{
int data;//數(shù)據(jù)域
struct Node*pNext;//指針域
};
intlen;//用來存放有效節(jié)點的個數(shù);
//第一部分:創(chuàng)建鏈表
structNode*Createe(){
structNode* pHead;
structNode*p1;
structNode*p2;
//int i;
intval;//用來臨時存放用戶的入的節(jié)點的值
// struct Node *pHead;//用來存放鏈表的頭節(jié)點
pHead=(structNode*)malloc(sizeof(structNode));
if(NULL== pHead){
printf("分配失敗荆永,程序終止\n");
exit(-1);
}
p1=pHead;
p1->pNext=NULL;
printf("請輸入你要輸入生成鏈表節(jié)點的個數(shù):len==");
scanf("%d",&len);
for(inti=0; i
printf("請輸入第%d個節(jié)點的值:",i+1);
scanf("%d",&val);
p2=(structNode*)malloc(sizeof(structNode));
if(NULL==p2){
printf("分配失敗废亭,程序終止!\n");
exit(-1);
}
p2->data=val;
p1->pNext=p2;
p2->pNext=NULL;
p1=p2;
}
returnpHead;
}
// 第二部分: 打印鏈表:#include "BinaryTreeNode.h"
voidpRintf(structNode* pHeader){
structNode* p=pHeader->pNext;
while(NULL!=p) {
printf("%d\n",p->data);
p=p->pNext;
}
}