c入門と第17章授業後のプログラミング3質問

/ * list.h(プログラムリスト17.5)の関数が新しい定義に適応し、films.c
(プログラムリスト17.4)を介して最終コードテストすると想定します。
#define MAXSIZE 100
typedef struct list
{
項目エントリ[MAZSIZE];
int items ;
}リスト;
新しい定義に適合するようにlist.cの関数を書き換え、
films.cとlist.hに変更を加えずに、list.cのコードのみを変更するため、変更された
list.c のみを送信する* /
#include“ list.h”
#include <stdio.h>
#include <stdlib.h>

/ インタフェース機能 /
/ 構造体アレイは、初期化の構造で配列要素の各メンバーのために取得するには、 /
空隙InitializeList(*リストのplist)
{
int型I;
(; I I = 0のための<MAXSIZE; I ++)
{
plist->エントリこれ[ i] .title [0] = '\ 0'; //配列メンバーの初期化
plist->エントリ[i] .rating = 0;
}
plist-> items = 0;

}

/ リンクリストが空の場合はtrueを返します /
bool ListIsEmpty(const List * plist)
{
if(plist == NULL)
return true;
else
return false;
}

/ リストがいっぱいの場合は、trueを返します /
bool ListIsFull(const List * plist)
{

bool full;


if(plist->items >= 100)
    full = true;
else
    full = false;

return full;

}

/ ノードの数を返し
ます/ unsigned int ListItemCount(const List * plist)
{
unsigned int count = plist-> items;

return count;

}

/ 情報を構造体配列に直接コピーします。情報がいっぱいの場合は、いっぱいであることを示します。/
bool AddItem(アイテムアイテム、リスト* plist)
{
plist->エントリ[plist->アイテム] =アイテム;
++ plist->アイテム;
if(ListIsFull(plist))
{
fprintf(stderr、“ No memory available!Bye !\ n”);
falseを返す;
}
それ以外は
trueを返す;
}

/ 各ノードにアクセスし、pfunが指す関数を実行します /
void Traverse(const List * plist、void(* pfun)(Item item))

int i;
for(i = 0; iitems; i ++)
(* pfun)(plist ->エントリ[i]);
}

/ *もはや使用する必要はありません* /
void EmptyTheList(List * plist)
{

}

オリジナルの記事を85件公開 Like1 Visits1889

おすすめ

転載: blog.csdn.net/Tekkenwxp/article/details/103499459