學習資料結構的第一天

2021-09-10 09:35:25 字數 1021 閱讀 9712

今天學習的是線性表之

//順序表

#include#include#define maxsize 100 //定義最大表長

typedef int elemtype;

typedef struct sqlist;

//建立空表

bool initlist(sqlist &l)

} i//按位置取值(第i個)

bool getelem(sqlist l, int i, elemtype &e)

//查詢返回序號

int locateelem(sqlist l, elemtype e)

return 0;

} //插入

bool listinsert(sqlist &l, int i, elemtype e)

l.elem[i-1] = e;

l.length++; //當前表長加一

return true;

} //刪除

bool listdelete(sqlist &l, int i)

l.length--;// 當前表長減一

return true;

}void print(sqlist l)

printf("\n");

}int main()

//列印

print(l1);

//取值

int e = 0;

if(!getelem(l1, 7, e)) printf("error\n");

else printf("%d \n", e);

//按值查詢

if(locateelem(l1, 5)) printf("%d \n", locateelem(l1, 5));

//插入

if(listinsert(l1, 6, 12)) print(l1);

//刪除

if(listdelete(l1, 10)) print(l1);

}

資料結構學習第一天

乙個好的程式需要選擇乙個合理的資料結構和乙個好的演算法,而乙個好的演算法離不開描述實際採用的資料結構 資料是描述客觀事物的集合 數與字元 是能被計算機輸入和處理的。資料物件是同一性質資料元素的集合,屬於資料的子集。資料元素通常作為資料的基本單位,在電腦程式中通常作為乙個整體進行考慮和處理。資料項是具...

1 資料結構第一天

1 2分法 不多介紹 2 有優先順序的運算 用left right sign這三個變數即可,加減算left,乘除算right。3 順腿法 逆推法 4 遞迴法 不建議採用,執行效率低。使用時應有遞迴出口 中止遞迴的判斷條件 5 分治演算法 問題分為若干小規模同類問題,當小問題足夠小,可以求解後。再按照...

redis 資料結構 String 第一天

10.1 string 10.1.1 設定單個key的值 命令 set key value ex seconds px milliseconds nx xx 例如 給 vv 設定值為 vv1 且生命週期為永久 set vv vv1 給 vv 設定值為 vv1 且生命週期為20秒 第一種方式 set ...