#ifndef slist_h_
#define slist_h_
#include #include #include typedef int sltdatatype;
typedef struct slistnode
slistnode;
typedef struct slist
slist;
void slistinit(slist* plist);
void slistdestory(slist* plist);
slistnode* buyslistnode(sltdatatype x);
void slistpushfront(slist* plist, sltdatatype x);
void slistpopfront(slist* plist);
slistnode* slistfind(slist* plist, sltdatatype x);
void slistinsertafter(slistnode* pos, sltdatatype x);// 在pos的後面進行插入
void slisteraseafter(slistnode* pos);// 在pos的前面進行插入
void slistremove(slist* plist, sltdatatype x);//作業:給乙個x,把這個結點刪除(練習鍊錶的遍歷)
void slistprint(slist* plist);
void testslist();
#endif
#ifndef _seqlist_h_
#define _seqlist_h_
typedef int sldatatype;
#include #include typedef struct seqlist
seqlist;
void seqlistinit(seqlist* psl, size_t capacity);
void seqlistdestory(seqlist* psl);
void checkcapacity(seqlist* psl);
void seqlistpushback(seqlist* psl, sldatatype x);
void seqlistpopback(seqlist* psl);
void seqlistpushfront(seqlist* psl, sldatatype x);
void seqlistpopfront(seqlist* psl);
int seqlistfind(seqlist* psl, sldatatype x);
void seqlistinsert(seqlist* psl, size_t pos, sldatatype x);
void seqlisterase(seqlist* psl, size_t pos);
void seqlistremove(seqlist* psl, sldatatype x);
void seqlistmodify(seqlist* psl, size_t pos, sldatatype x);
void seqlistprint(seqlist* psl);
void seqlistbubblesort(seqlist* psl);
int seqlistbinaryfind(seqlist* psl, sldatatype x);// 本題要求:時間複雜度:o(n) 空間複雜度 o(1)
void seqlistremoveall(seqlist* psl, sldatatype x);//作業:先排序->(去重,1 3 3 3 4 5->1 3 4 5)
#endif //_seqlist_h_
#include "slist.h"
void slistinit(slist* plist)//初始化乙個頭結點
void slistpushfront(slist* plist, sltdatatype x)//頭插
void slistpopfront(slist* plist)//頭刪
}void slistprint(slist* plist)//列印鍊錶
printf("null\n");
}void slistdestory(slist* plist)//釋放鍊錶
}slistnode* slistfind(slist* plist, sltdatatype x)//查詢乙個節點,並且返回位置
} return null;
}void slistinsertafter(slistnode* pos, sltdatatype x)//在pos的後面插入結點
//void slistinsertfront(slist * plist, sltdatatype x)//在pos的前面插入結點
//// for (cur = plist->_head; cur->_next; cur = cur->_next)
// // }
// newdata->_next = cur->_next;
// cur->_next = newdata;
//}void slisteraseafter(slistnode* pos)//在pos的後面刪除結點
#include "seqlist.h"
#include void seqlistinit(seqlist* psl, size_t capicity)//初始化
void seqlistdestory(seqlist* psl)//銷毀函式
}void checkcapacity(seqlist* psl)//擴容函式
}void seqlistpushback(seqlist* psl, sldatatype x)//尾插
void seqlistpopback(seqlist* psl)//尾刪
void seqlistpushfront(seqlist* psl, sldatatype x)//頭插
psl->array[0] = x;
psl->size++;
}void seqlistpopfront(seqlist* psl)//頭刪
}void seqlistprint(seqlist* psl)//輸出
putchar('\n');
}int seqlistfind(seqlist* psl, sldatatype x)//查詢
} return -1;
}void seqlistinsert(seqlist* psl, size_t pos, sldatatype x)//按位置插入資料
psl->array[pos] = x;
psl->size++;
}void seqlisterase(seqlist* psl, size_t pos)//按位置刪除
}void seqlistremove(seqlist* psl, sldatatype x)//刪除含有x裡面的資料
}void seqlistmodify(seqlist* psl, size_t pos, sldatatype x)//將pos位置的資料替換為x
void seqlistbubblesort(seqlist* psl)//氣泡排序
} }}int seqlistbinaryfind(seqlist* psl, sldatatype x)// 本題要求:時間複雜度:o(n) 空間複雜度 o(1)
else if (psl->array[mid]>x)
else
}return -1;
}
#include "seqlist.h"
#include "slist.h"
void listtest()
/*int main()
*/int main()
資料結構《順序鍊錶》
include using namespace std template class sqlist template sqlist sqlist int m template sqlist sqlist template void sqlist createlist int n template t...
資料結構 順序表的基本操作
計算機中線性表的存放結構主要有兩種 順序儲存結構和鏈式儲存結構。採用前者存放方式的線性表是順序表,採用後者的就是我們平時所說的鍊錶 線性鍊錶 這裡先對順序表的一些基本操作進行歸納和總結,鍊錶的將在後面的文章中歸納總結。順序表的表示,一般都是借助一維陣列。c 語言定義其結構如下 const int m...
資料結構 順序表的基本操作
main include include define true 1 define error 0 define ok 1 define false 0 define overflow 2 typedef int status typedef int elemtype define list ini...