動態表的基本實現

2021-07-25 07:18:26 字數 2848 閱讀 8924

#pragma once

#include#include#include#includetypedef int datatype;

typedef struct seqlist

seqlist;

void initseqlist(seqlist* seq);

void destoryseqlist(seqlist* seq);

void checkcapacity(seqlist *seq);

void pushback(seqlist* seq,datatype x);

void popback(seqlist* seq);//尾插尾刪

void pushfront(seqlist* seq, datatype x);

void popfront(seqlist* seq, datatype x);//頭插頭刪

void insert(seqlist* seq,size_t pos, datatype x);//指定位置插入

void delete(seqlist* seq,size_t pos);//指定位置刪除

void erase(seqlist* seq, datatype x);//刪除資料

void removeall(seqlist* seq, datatype x);//刪除全部指定元素

int search(seqlist* seq, datatype x);//查詢元素

void bubblesort(seqlist* seq);//氣泡排序

void selectsort(seqlist* seq);//選擇排序

void insertsort(seqlist* seq);//插入排序

int binaryseach(seqlist* seq, datatype x);//二分查詢

#include"seq.h"

void initseqlist(seqlist* seq)

void destory(seqlist* seq)

seq->arry = null;

seq->capacity = 0;

seq->size = 0;

}void checkcapacity(seqlist *seq)

}void pushback(seqlist* seq, datatype x)

void popback(seqlist* seq)

seq->size--;

}void pushfront(seqlist* seq, datatype x)

seq->size++;

seq->arry[0] = x;

}void popfront(seqlist* seq)

for (size_t i = 0; i < seq->size; i++)

seq->size--;

}void insert(seqlist* seq,size_t pos,datatype x)

seq->size++;

seq->arry[pos - 1] = x; }

void delete(seqlist* seq, size_t pos)//指定位置刪除

for (i = pos-1; i < seq->size-1;i++)

seq->size--;

}int search(seqlist* seq, datatype x)

else }

return -1; }

}void erase(seqlist* seq, datatype x)

else

else

}/* }

return -1;

}*/}void removeall(seqlist* seq, datatype x)

int i = 0;

int j = 0;

int count = 0;

for (i = 0; j < seq->size; i++)

else

}seq->size -= count;

}int swap(int *a, int *b)

void bubblesort(seqlist* seq)

size_t i = 0;

size_t j = 0;

for (i = 0; i < seq->size; i++) }

}void selectsort(seqlist* seq)

int start = 0;

int end = seq->size - 1;

while (start <= end)

swap(&(seq->arry[start]), &(seq->arry[min]));

if (max == start)

swap(&(seq->arry[end]), &(seq->arry[max]));

start++;

end--; }}

void insertsort(seqlist* seq)

for (size_t i = 0; i < seq->size - 1; i++)

seq->arry[end + 1] = temp; }}

int binaryseach(seqlist* seq, datatype x)

int start = 0;

int end = seq->size - 1;

while (start <= end)

else if (seq->arry[mid]>x)

else

return mid + 1;

} return -1;

}

動態順序表的基本實現

include include define list init size 100 define listincrement 10 define status int define overflow 1 define ok 1 define error 0 define elemtype int t...

動態順序表的基本操作

seqlistd.h pragma once include include include typedef int datatype typedef struct seqlistd seqlistd,pseqlistd void seqlistdinit pseqlistd ps,int capa...

動態交叉表的實現

declare sql varchar 8000 set sql select makedate,select sql sql sum case status when status then status else 0 end as status from select distinct stat...