📄 arraylist.c
字号:
#include "mystdlib.h"#include "error.h"#include "nat.h"#include "commonInter.h"#include "arrayList.h"#define initLength 32#define extFactor 2arrayList newArrayList (){ arrayList p = checkedMalloc (sizeof (*p)); p->array = checkedMalloc (initLength * sizeof (poly)); p->maxItems = initLength; p->tail = 0; return p;}int arrayListIsEmpty (arrayList l){ return (l->tail == 0);}poly arrayListHead (arrayList l){ if (l->tail == 0) exception ("list is empty\n"); return (l->array)[0];}int arrayListSize (arrayList l){ return (l->tail);}void arrayListInsert (arrayList l, poly x, int i){ if (l->maxItems == l->tail) { l->array = checkedRealloc (l->array, extFactor * (l->maxItems) * sizeof (poly)); l->maxItems *= extFactor; } else; for (int j=l->tail-1; j>=i; j--) (l->array)[j+1] = (l->array)[j]; (l->array)[i] = x; (l->tail)++; return;}poly arrayListDelete (arrayList l, int i){ if (i<0 || i>=l->maxItems) exception ("index out of bound\n"); poly temp = (l->array)[i]; for (int j=i; j<l->tail; j++) (l->array)[j] = (l->array)[j+1]; l->tail--; return temp;}void arrayListForeach (arrayList l, void (*f)(poly)){ for (int i=0; i<l->tail; i++) f ((l->array)[i]); return;}void arrayListOutput (arrayList l){ for (int i=0; i<l->tail; i++) { strOutput (strConcat (strConcat ( natToString (newNat (i)), newStr (" -> ")), getVft (l->array[i])->toString (l->array[i]))); } return;}poly arrayListLookup (arrayList l, int index){ if (index<0 || index>=l->tail) { //printf ("index=%d, l->tail=%d\n", index, l->tail); exception ("index out of bound in array list\n"); } return (*(l->array+index));}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -