6 1 順序表操作集 20 分

2021-10-21 06:57:20 字數 3198 閱讀 4625

6-1 順序表操作集 (20 分)

本題要求實現順序表的操作集。

函式介面定義:

list makeempty()

; position find

( list l, elementtype x )

;bool insert

( list l, elementtype x, position p )

;bool delete

( list l, position p )

;

其中list結構定義如下:

typedef

int position;

typedef

struct lnode *list;

struct lnode

;

各個操作函式的定義為:

list makeempty

():建立並返回乙個空的線性表;

position find

( list l, elementtype x ):返回線性表中x的位置。若找不到則返回error;

bool insert

( list l, elementtype x, position p ):將x插入在位置p並返回true。若空間已滿,則列印「full」並返回false;如果引數p指向非法位置,則列印「illegal position」並返回false;

bool delete

( list l, position p ):將位置p的元素刪除並返回true。若引數p指向非法位置,則列印「position p empty」(其中p是引數值)並返回false。

裁判測試程式樣例:

#include

#include

#define maxsize 5

#define error -1

typedef

enum

bool;

typedef

int elementtype;

typedef

int position;

typedef

struct lnode *list;

struct lnode

;list makeempty()

; position find

( list l, elementtype x )

;bool insert

( list l, elementtype x, position p )

;bool delete

( list l, position p )

;int

main()

scanf

("%d"

,&n)

;while

( n--

)scanf

("%d"

,&n)

;while

( n--

)return0;

}

/* 你的**將被嵌在這裡 */

輸入樣例:

612

3456

3651

2-16

輸出樣例:

full insertion error:

6 is not in.

finding error:

6 is not in.

5 is at position 0.

1 is at position 4.

position -

1 empty deletion error.

full insertion error:

0 is not in.

position 6 empty deletion error.

full insertion error:

0 is not in.

#include #include #define maxsize 5

#define error -1

typedef enum bool;

typedef int elementtype;

typedef int position;

typedef struct lnode *list;

struct lnode ;

list makeempty();

position find( list l, elementtype x );

bool insert( list l, elementtype x, position p );

bool delete( list l, position p );

int main()

scanf("%d", &n);

while ( n-- )

scanf("%d", &n);

while ( n-- )

return 0;

}///建立並返回乙個空的線性表;

list makeempty()

///返回線性表中x的位置。若找不到則返回error;

position find( list l, elementtype x )

}return error;

}/**將x插入在位置p並返回true。若空間已滿,則列印「full」並返回false;

如果引數p指向非法位置,則列印「illegal position」並返回false;*/

bool insert( list l, elementtype x, position p )

if(p<0||p>l->last+1)

int i;

for(i = l->last+1; i > p; i--)

l->data[i] = x;//插入

l->last++;//個數增加

return true;

}/**將位置p的元素刪除並返回true。若引數p指向非法位置,

則列印「position p empty」(其中p是引數值)並返回false。*/

bool delete( list l, position p )

for(i = p; i < l->last; i++)

l->last--;//減少乙個

return true;

}

順序表操作集 20 分

本題要求實現順序表的操作集。list makeempty position find list l,elementtype x bool insert list l,elementtype x,position p bool delete list l,position p 其中list結構定義如下...

順序表操作集 20 分

本題要求實現順序表的操作集。函式介面定義 list makeempty position find list l,elementtype x bool insert list l,elementtype x,position p bool delete list l,position p 其中lis...

6 1 順序表操作集

list makeempty position find list l,elementtype x bool insert list l,elementtype x,position p bool delete list l,position p 其中list 結構定義如下 typedef int ...