Programming Abstractions in C閱讀筆記:p331-p337

codists發表於2024-03-21

《Programming Abstractions in C》學習第79天,p331-p337,總計7頁。

一、技術總結

/*
 * File: stack.h
 * -------------
 * This interface defines an abstraction for stacks. In any
 * single application that uses this interface, the values in
 * the stack are constrained to a single type, although it
 * is easy to change that type by changing the definition of
 * stackElementT in this interface.
 */

#ifndef _stack_h
#define _stack_h

#include "genlib.h"

/*
 * Type: stackElementT
 * -------------------
 * The type stackElementT is used in this interface to indicate
 * the type of values that can be stored in the stack. Here the
 * stack is used to store values of type double, but that can
 * be changed by editing this definition line.
 */

typedef double stackElementT;

/*
 * Type: stackADT
 * --------------
 * The type stackADT represents the abstract typed used to store
 * the elements that have been pushed. Because stackADT is
 * defined only as a pointer to a concrete structure that is not
 * itself defined in the interface, clients have no access to
 * the underlying fields.
 */

typedef struct stackCDT *stackADT;

/*
 * Function: NewStack
 * Usage: stack = NewStack();
 * --------------------------
 * This function allocates and returns a new stack, which is
 * initially empty.
 */

stackADT NewStack(void);

/*
 * Function: FreeStack
 * Usage: FreeStack(stack);
 * ------------------------
 * This function free the storage associated with the stack.
 */

void FreeStack(stackADT stack);

/*
 * Function: Push
 * Usage: Push(stack, element);
 * ----------------------------
 * This function pushes the specified element onto the stack;
 */
void Push(stackADT stack, stackElementT element);


/*
 * Function: Pop
 * Usage: element = Pop(stack);
 * -----------------------------
 * This function pops the top element from the stack and returns
 * that value. The first value popped is always the last one
 * that was pushed. If the stack is empty when Pop is called,
 * the function calls Error with an appropriate message.
 */

stackElementT Pop(stackADT stack);


/*
 * Function: StackIsEmpty, StackIsFull
 * Usage: if (StackIsEmpty(stack)) ...
 *        if (StackIsFull(stack)) ...
 * ---------------------------------------
 * This function test whether the stack is empty or full.
 */

bool StackIsEmpty(stackADT stack);
bool StackIsFull(stackADT stack);

/*
 * Function: StackDepth
 * Usage: depth = StackDepth(stack);
 * ---------------------------------
 * This function returns the number of elements currently pushed
 * on the stack.
 */
int StackDepth(stackADT stack);


/*
 * Function: GetStackElement
 * Usage: element = GetStackElement(stack, index);
 * -----------------------------------------------
 * This function returns the element at the specified index in
 * the stack, where the top of the stack is defined as index 0.
 * For example, calling GetStackElement(stack, 0) returns the top
 * element on the stack without removing it. If the caller tries
 * to select an out-of-range element, GetStackElement calls Error.
 * Note: This function is not a fundamental stack operation and
 * is instead provided principally to facilitate debugging.
 */
stackElementT  GetStackElement(stackADT stack, int index);

#endif

二、英語總結

1.polymorphism是什麼意思?

答:

(1)polymorphous > polymorph > polymorphism

(2)polymorphous: poly"many" + morphē "shape, form,"。adj. have various forms。

(3)polymorphism: capability of existing in different forms(多型性)。

p332, the ability to apply the same function to objects of different types called polymorhpism。

2.overhead用法總結

答:

(1)n. the regular and necessary costs(開銷)。p332, In some cases, however, forcing the clients to use pointer as data values imposes an unacceptable level of overhead.

平時大多做副詞用,也可以做名詞。

3.compromise是什麼意思?

答:com-(together) + promise,c/u. a joint promise to abide by an arbiter's decision(妥協)。 abide by sth: to accept or obey an aggrement。

4.as far as sth is concerned是什麼意思?

答:If we are discussing or thinking about a particular thing(就......而言)。

5.relinquish是什麼意思?

答:vt. to give up sth such as responsibility or claim(放棄,捨棄)。p335, Thus, in addition to the function NewStack, you need a symmetric funciton FreeStack, that takes a buffer and relinquishes any dynamically allocated storage it contains。

三、其它

並不是每一篇文章都是有意義的,這只是學習過程的一個記錄。

四、參考資料

1. 程式設計

(1)Eric S.Roberts,《Programming Abstractions in C》:https://book.douban.com/subject/2003414

2. 英語

(1)Etymology Dictionary:https://www.etymonline.com

(2) Cambridage Dictionary:https://dictionary.cambridge.org

歡迎搜尋及關注:程式設計人(a_codists)

相關文章