順序表 簡單功能

2021-07-03 09:10:22 字數 4057 閱讀 7830

#ifndef _seqlist_h

#define _seqlist_h

#include#include#includeusing namespace std;

#define elemtype int

#define seqlist_default_size 10

typedef struct seqlist

seqlist;

bool empty(seqlist *list);

bool full(seqlist *list);

void initseqlist(seqlist *list);

bool push_front(seqlist *list,elemtype x);

bool push_back(seqlist *list,elemtype x);

bool pop_back(seqlist *list);

bool pop_front(seqlist *list);

bool insert_pos(seqlist *list,int pos,elemtype x);

bool insert_val(seqlist *list,elemtype x);

bool delete_pos(seqlist *list,int pos);

bool delete_val(seqlist *list,elemtype x);

int find(seqlist *list,elemtype x);

int getvalue(seqlist *list,int pos);

bool modify(seqlist *list,elemtype item,elemtype x);

bool clear(seqlist *list);

bool destroy(seqlist *lsit);

bool sort(seqlist *list);

int length(seqlist *list);

int next(seqlist *list,elemtype item);

int prio(seqlist *list,elemtype item);

void show_seqlist(seqlist *list);

#endif

#include"seqlist.h"

void initseqlist(seqlist *list)

bool empty(seqlist *list) //判斷是否空

bool full(seqlist *list) //判斷是否滿

int prio(seqlist *list,elemtype item) //查詢前驅

int next(seqlist *list,elemtype item) //查詢後繼

int length(seqlist *list) //求長度

bool sort(seqlist *list) //冒泡法排序

} return true;

}bool destroy(seqlist *list) //摧毀鍊錶

bool clear(seqlist *list) //清除

bool modify(seqlist *list,elemtype item,elemtype x) //修改

int getvalue(seqlist *list,int pos) //按位置查詢值

int find(seqlist *list,elemtype x) //按值查詢位置

return -1;

}bool delete_val(seqlist *list,elemtype x) //按值刪除

} cout<<"要刪除的值不存在"size)

list->size--;

return true;

}bool insert_val(seqlist *list,elemtype x) //按值插入

list->size++;

list->base [i+1]=x;

return true;

} }return false;

}bool insert_pos(seqlist *list,int pos,elemtype x) //按位置插入

list->base [pos]=x;

list->size++;

return true;

}bool pop_front(seqlist *list) //頭刪法

list->size--;

return true;

}bool pop_back(seqlist *list) //尾刪法

bool push_back(seqlist *list,elemtype x) //尾插法

bool push_front(seqlist *list,elemtype x) //頭插法

list->base[0]= x;

list->size++;

return true;

}void show_seqlist(seqlist *list) //輸出鍊錶

cout<#include"seqlist.h"

using namespace std;

void main()

break;

case 2:

cout<<"請輸入要插入的資料:>";

while(cin>>item,item!=-1)

break;

case 3:

show_seqlist(&mylist);

break;

case 4:

pop_back(&mylist);

break;

case 5:

pop_front(&mylist);

break;

case 6:

cout<<"輸入要插入的位置:>";

cin>>pos;

cout<<"請輸入要插入的資料:>";

cin>>item;

insert_pos(&mylist,pos,item);

break;

case 7:

cout<<"請輸入要插入的資料:>";

cin>>item;

insert_val(&mylist,item);

break;

case 8:

cout<<"請輸入要刪除的位置:>";

cin>>pos;

delete_pos(&mylist,pos);

break;

case 9:

cout<<"請輸入要刪除的值:>";

cin>>item;

delete_val(&mylist,item);

break;

case 10:

cout<<"請輸入要查詢的值:>";

cin>>item;

pos = find(&mylist,item);

cout<<"位置為:>"<";

cin>>pos;

item = getvalue(&mylist,pos);

cout<<"獲得的值"<";

cin>>item;

cout<<"輸入修改後的值:>";

cin>>x;

modify(&mylist,item,x);

break;

case 13:

clear(&mylist);

cout<<"清除完成"<"<";

cin>>item;

pos = next(&mylist,item);

cout<<"後繼為:>"<";

cin>>item;

pos = prio(&mylist,item);

cout<<"前驅為:>"

default:

cout<<"你輸入的是個什麼啊!"

} }}

資料結構 順序表簡單功能實現

標頭檔案seqlist.h 包含了順序表的增刪查改以及氣泡排序和二分法及一些簡單功能實現 pragma once include typedef int sldatatype typedef struct seqlist seqlist 基本增刪查改介面 初始化 void seqlistinit s...

順序表的功能實現

順序表的建立,插入,刪除,清空,銷毀,查詢,輸出功能 include include include definetrue 1 definefalse 0 defineok 1 defineerror 0 defineinfeasible 1 defineoverflow 2 typedefint ...

簡單的順序表

include include define init size 100 順序表初始化大小 define incess size 20 順序表滿後的每次擴充大小 define ok 0 define error 1 define malloc error 2 typedef int elementt...