CTlvEsM7Ap::~CTlvEsM7Ap() { LPLISTITR itr; CTlvNwKeyIndex *keyIndex; CTlvNwKey *key; itr = ListItrCreate(nwKeyIndex); if(!itr) throw WSC_ERR_OUTOFMEMORY; while((keyIndex = (CTlvNwKeyIndex *)ListItrGetNext(itr))) { delete keyIndex; } ListItrDelete(itr); ListDelete(nwKeyIndex); itr = ListItrCreate(nwKey); if(!itr) throw WSC_ERR_OUTOFMEMORY; while((key = (CTlvNwKey *)ListItrGetNext(itr))) { delete key; } ListItrDelete(itr); ListDelete(nwKey); }
int main(void) { /// create list SqList List; InitList(&List); /// insert element to list ListInsert(&List, 1, 1); ListInsert(&List, 2, 2); ListInsert(&List, 3, 3); ListInsert(&List, 4, 4); ListInsert(&List, 5, 5); /// locate element printf("element %d is in %d\n", 4, LocateElem(&List, 4)); /// list length int length = ListLength(&List); printf("List length is %d\n", length); /// get list element int i, element; for (i = 1; i <= length; i++) { GetElem(&List, i, &element); printf("element in %d is %d\n", i, element); } /// delect element from list ListDelete(&List, 4, &element); printf("deleted element in %d is %d\n", 4, element); /// clear list ClearList(&List); printf("List empty is %d\n", ListEmpty(&List)); return EXIT_SUCCESS; }
//Waits time milliseconds until returning (current thread only) TimerTime TimerSleep(TimerTime time) { //Calculate wake up time time += currentTime; //Create entry TimerQueue * newQueueEntry = MemKAlloc(sizeof(TimerQueue)); newQueueEntry->thread = ProcCurrThread; newQueueEntry->endTime = time; //Add to queue AddTimerToQueue(newQueueEntry, &sleepQueueHead); //Block thread if(ProcYieldBlock(true)) { //Interrupted, we must manually remove the queue entry ListDelete(&newQueueEntry->list); MemKFree(newQueueEntry); //Return difference between current time and given time return currentTime - time; } //If uninterrupted, the queue has already been freed return 0; }
void main() { SqList *L; ElemType e; printf("(1)初始化顺序表L\n"); InitList(L); printf("(2)依次采用尾插法插入a,b,c,d,e元素\n"); ListInsert(L,1,'a'); ListInsert(L,2,'b'); ListInsert(L,3,'c'); ListInsert(L,4,'d'); ListInsert(L,5,'e'); printf("(3)输出顺序表L:"); DispList(L); printf("(4)顺序表L长度=%d\n",ListLength(L)); printf("(5)顺序表L为%s\n",(ListEmpty(L)?"空":"非空")); GetElem(L,3,e); printf("(6)顺序表L的第3个元素=%c\n",e); printf("(7)元素a的位置=%d\n",LocateElem(L,'a')); printf("(8)在第4个元素位置上插入f元素\n"); ListInsert(L,4,'f'); printf("(9)输出顺序表L:"); DispList(L); printf("(10)删除L的第3个元素\n"); ListDelete(L,3,e); printf("(11)输出顺序表L:"); DispList(L); printf("(12)释放顺序表L\n"); DestroyList(L); }
int main(void) { ElemType site[11] = { 'a', 'n', 'o', 't', 'h', 'e', 'r', 'h', 'o', 'm', 'e' }; LinkList *Link, *LinkR; ElemType e; CreateListF(Link, site, 11); CreateListR(LinkR, site, 11); DispList(Link); DispList(LinkR); DestroyList(LinkR); if (ListEmpty(Link)) { printf("List is empty\n"); } else { printf("List isn't empty\n"); } printf("ListLength: %d\n", ListLength(Link)); GetElem(Link, ListLength(Link), e); ListInsert(Link, 2, e); DispList(Link); ListDelete(Link, 3, e); DispList(Link); printf("The location of 'o' is %d\n", LocateElem(Link, 'o')); DestroyList(Link); return 0; }
VOID _IncreaseBlockReference(PCACHE_POOL CachePool, PCACHE_BLOCK pBlock) { PCACHE_BLOCK _pBlock, Top; if (pBlock->Protected == TRUE) { ListMoveToHead(&CachePool->ProtectedList, pBlock); } else { ListDelete(&CachePool->ProbationaryList, pBlock); CachePool->Probationary_bpt_root = Delete(CachePool->Probationary_bpt_root, pBlock->Index, FALSE); // Protected is Full if (CachePool->ProtectedList.Size == CachePool->ProtectedSize) { // Remove one from Protected _pBlock = ListRemoveTail(&CachePool->ProtectedList); CachePool->Protected_bpt_root = Delete(CachePool->Protected_bpt_root, _pBlock->Index, FALSE); // Move to Probationary // Probationary Obviously Not Full for We just Remove one from it _pBlock->Protected = FALSE; ListInsertToHead(&CachePool->ProbationaryList, _pBlock); CachePool->Probationary_bpt_root = Insert(CachePool->Probationary_bpt_root, _pBlock->Index, _pBlock); } // Add to Protected pBlock->Protected = TRUE; ListInsertToHead(&CachePool->ProtectedList, pBlock); CachePool->Protected_bpt_root = Insert(CachePool->Protected_bpt_root, pBlock->Index, pBlock); } }
int main() { StaticLinkList L; Status i; i=InitList(L); printf("初始化L后:L.length=%d\n",ListLength(L)); i=ListInsert(L,1,'F'); i=ListInsert(L,1,'E'); i=ListInsert(L,1,'D'); i=ListInsert(L,1,'B'); i=ListInsert(L,1,'A'); printf("在L的表头依次插入FEDBA后:\nL.data="); ListTraverse(L); i=ListInsert(L,3,'C'); printf("\n在L的“B”与“D”之间插入“C”后:\nL.data="); ListTraverse(L); i=ListDelete(L,1); printf("\n在L的删除“A”后:\nL.data="); ListTraverse(L); printf("\n"); return 0; }
static void SortAndMakeUserFontNameList( void ) { UInt16 i; DBEntryType* dbListEntry; DBEntryType** userFontArray; currentUserFontNumber = NO_SUCH_USER_FONT; ClearUserFontNameList(); if ( userFontDBList == NULL ) return; numberOfUserFonts = ListSize( userFontDBList ); if ( numberOfUserFonts == 0 ) return; userFontArray = SafeMemPtrNew( numberOfUserFonts * sizeof( DBEntryType* ) ); userFontNames = SafeMemPtrNew( numberOfUserFonts * sizeof( Char* ) ); dbListEntry = ListFirst( userFontDBList ); for ( i = 0; i < numberOfUserFonts ; i++ ) { userFontArray[ i ] = dbListEntry; dbListEntry = ListNext( userFontDBList, dbListEntry ); } SysQSort( userFontArray, numberOfUserFonts, sizeof( DBEntryType* ), DBEntryCompare, 0 ); ListDelete( userFontDBList ); userFontDBList = ListCreate(); for ( i = 0 ; i < numberOfUserFonts ; i++ ) { ListAppend( userFontDBList, userFontArray[ i ] ); userFontNames[ i ] = userFontArray[ i ]->name; } SafeMemPtrFree( userFontArray ); }
void main() { DLinkList *h; ElemType e; printf("(1)初始化循环双链表h\n"); InitList(h); printf("(2)依次采用尾插法插入a,b,c,d,e元素\n"); ListInsert(h,1,'a'); ListInsert(h,2,'b'); ListInsert(h,3,'c'); ListInsert(h,4,'d'); ListInsert(h,5,'e'); printf("(3)输出循环双链表h:"); DispList(h); printf("(4)循环双链表h长度=%d\n",ListLength(h)); printf("(5)循环双链表h为%s\n",(ListEmpty(h)?"空":"非空")); GetElem(h,3,e); printf("(6)循环双链表h的第3个元素=%c\n",e); printf("(7)元素a的位置=%d\n",LocateElem(h,'a')); printf("(8)在第4个元素位置上插入f元素\n"); ListInsert(h,4,'f'); printf("(9)输出循环双链表h:"); DispList(h); printf("(10)删除h的第3个元素\n"); ListDelete(h,3,e); printf("(11)输出循环双链表h:"); DispList(h); printf("(12)释放循环双链表h\n"); DestroyList(h); }
int main() { struct SqList L; InitList(&L); printf("ListEmpty(L) = %d\n", ListEmpty(L)); printSqList(L); int e; int index = 7; GetElem(L, index, &e); printf("the %d th number is e : %d\n", index, e); printf("Find %d at index %d\n", e, Locate(L, e)); int insertNum = 100; ListInsert(&L, index, 100); printf("Insert %d at index %d into SqList\n", insertNum, index); printSqList(L); ListDelete(&L, index, &e); printf("Delete %d at index %d from SqlList\n", e, index); printSqList(L); printf("ListLength(L) = %d\n", ListLength(L)); ClearList(&L); printf("ListEmpty(L) = %d\n", ListEmpty(L)); printSqList(L); return 0; }
int main(int argc, char *argv[]) { DataType a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9,}; DataType b[] = {10, 11, 12, 13, 14, 15}; DataType e; CirList A; /* 声明循环链表A和B */ CirList B; p_CirList C = NULL; InitList(&A); /* 初始化 */ InitList(&B); C = &A; /* 插入元素 */ Insert_Elem(&A, a, sizeof(a) / sizeof(DataType)); Insert_Elem(&B, b, sizeof(b) / sizeof(DataType)); printf("循环链表A中有%d个元素\n", ListLength(A)); ListTraverse(A, Show_Elem); putchar('\n'); printf("循环链表B中有%d个元素\n", ListLength(B)); ListTraverse(B, Show_Elem); puts("\n\n"); if (GetElem(&A, 8, &e)) printf("循环链表A第8个元素是%4d\n", e); if (GetElem(&B, 5, &e)) printf("循环链表B第5个元素是%4d\n", e); putchar('\n'); printf("删除链表B最后一个元素\n"); ListDelete(&B, 6, &e); ListTraverse(B, Show_Elem); putchar('\n'); C = Merge(&A, &B); /* 合并 */ printf("合并后的链表有%d个元素\n", ListLength(*C)); ListTraverse(*C, Show_Elem); putchar('\n'); if (GetElem(C, 14, &e)) printf("合并后的链表第14个元素是%4d\n", e); ClearList(&A); ClearList(&B); putchar('\n'); exit(EXIT_SUCCESS); }
int main() { List list; InitList(&list); printf("创建线性表后线性表的当前长度:%d\n", list.length); printf("ListTraverse:"); //initialize int j; for(j = 0; j < 10; j++) { list.elem[j] = j; list.length++; } printf("after sqlist inited: %d=====%d\n", list.listsize, list.length); //test DestoryList /*DestoryList(&list); printf("After Destory List %d=====%d\n", list.listsize, list.length);*/ //test ListEmpty(List *list); printf("Is List Empty? %s\n", ListEmpty(&list) ? "true" : "false"); //test GetElem(List *list, int i, ElemType *e) ElemType e1; if(GetElem(&list, 3, &e1) ) { printf("Get index 3 element from list: %d\n", e1); } /*for(j = 0; j < list.length; j++) { if(list.elem[j] == 3) printf("i found %d in list index %d\n", 3, j); }*/ //test LocateElem ElemType e2 = 3; int position = LocateElem(&list, &e2); printf("%d\n", position); if (position >= 0) printf("I find e2 in list, it's index is %d\n", position); else printf("Not Found!\n"); //test ListInsert(List *list, int i, ElemType *e); ElemType e3 = 100; if(ListInsert(&list, 2, &e3)) { ListTraverse(&list); } //test BOOL ListDelete ElemType e4; if(ListDelete(&list, 2, &e4)) { printf("Delete index %d ElemType %d success\n", 1, e4); } ListTraverse(&list); return 0; }
/** * Delete one Block from Cache Pool and Free it */ VOID _DeleteOneBlockFromPool(PCACHE_POOL CachePool, LONGLONG Index) { PCACHE_BLOCK pBlock; if (_QueryPoolByIndex(CachePool, Index, &pBlock) == TRUE) { StoragePoolFree(&CachePool->Storage, pBlock->StorageIndex); if (pBlock->Protected == TRUE) { ListDelete(&CachePool->HotList, pBlock); CachePool->hot_bpt_root = Delete(CachePool->hot_bpt_root, Index, TRUE); } else { ListDelete(&CachePool->ColdList, pBlock); CachePool->cold_bpt_root = Delete(CachePool->cold_bpt_root, Index, TRUE); } CachePool->Used--; } }
//Merge1 void MergeList1(SLinkList L) { int n=10; int i=0; ElemType e; int j=0; InitList(L); printf("请输入A中数据的个数:"); scanf("%d",&i); if(i>0) n=i; for(i=0;i<n;i++) { loop: scanf("%d",&e); if(!LocateElem(L,e,compare)) ListInsert(L,i+1,e); else { printf("已存在,请重新输入:"); goto loop; } } printf("遍历链表"); TraverseList(L,visit); printf("\n"); printf("请输入B中数据的个数:"); scanf("%d",&i); if(i>0) n=i; for(i=0;i<n;i++) { scanf("%d",&e); if(!(j=LocateElem(L,e,compare))) { ListInsert(L,ListLength(L)+1,e); } else { ListDelete(L,j,e); } } printf("遍历链表"); TraverseList(L,visit); printf("\n"); }
EStatus StationDestroy(Station* pThis) { BEGIN_FUNCTION; VALIDATE_ARGUMENTS(pThis); CHECK(StationReset(pThis)); CHECK(SchedulerDelete(&pThis->pScheduler)); CHECK(ListDelete(&pThis->pOutbox)); CHECK(RoutingDelete(&pThis->pRouting)); END_FUNCTION; return eSTATUS_COMMON_OK; }
void GetPowerSet(int i, List A, List &B) { // 算法6.15 // 线性表A表示集合A,线性表B表示幂集ρ(A)的一个元素。 // 局部量k为进入函数时表B的当前长度。 // 第一次调用本函数时,B为空表,i=1。 ElemType x; int k; if (i > ListLength(A)) Output(B); // 输出当前B值,即ρ(A)的一个元素 else { GetElem(A, i, x); k = ListLength(B); ListInsert(B, k+1, x); GetPowerSet(i+1, A, B); ListDelete(B, k+1, x); GetPowerSet(i+1, A, B); } } // GetPowerSet
void main() { DuLinkList L; int i,n=2; ElemType e; InitList(&L); printf("初始化链表依次输入1,2,3,4,5\n"); for(i=1;i<=5;i++) ListInsert(L,i,i); /* 在第i个结点之前插入i */ ListDelete(L,n,&e); /* 删除并释放第n个结点 */ printf("删除第%d个结点,值为%d,其余结点为:",n,e); ListTraverse(L,vd); /* 正序输出 */ }
CTlvEsM8Sta::~CTlvEsM8Sta() { LPLISTITR itr; CTlvCredential *pCredential; if(!(itr = ListItrCreate(credential))) throw WSC_ERR_OUTOFMEMORY; while((pCredential = (CTlvCredential *)ListItrGetNext(itr))) delete pCredential; ListItrDelete(itr); ListDelete(credential); }
int main(void) { SqList L; ElemType e; SetNull(&L); append_arr(&L, 3); append_arr(&L, 2); append_arr(&L, 6); append_arr(&L, 2); ListDelete(&L, 2, &e); DisLisy(&L); printf("\n\n%d", e); return 0; }
int main(void) { int choice = 0, loopflag = 1; char NewData[255], OldData[255]; printf("原串列 :\n"); PrintList(table); while (loopflag) { printf("(1)插入節點,(2)刪除節點, (其它鍵) 離開 =>"); scanf("%d", &choice); switch (choice) { case 1: printf("\n請輸入欲插入之資料=>"); scanf("%s", NewData); strupr(NewData); printf("請輸入欲插入那一資料之後 ( 輸入HEAD代表成為第一個資料 ) =>"); scanf("%s", OldData); strupr(OldData); if (InsertAfter(table, OldData, NewData) == FALSE) { printf("插入失敗\n"); break; } printf("插入 %s 之後的串列 :\n", NewData); PrintList(table); break; case 2: printf("\n請輸入欲刪除那一資料=>"); scanf("%s", OldData); strupr(OldData); if (ListDelete(table, OldData) == FALSE) { printf("找不到資料,刪除失敗\n"); break; } printf("刪除 %s 之後的串列 :\n", OldData); PrintList(table); break; default: loopflag = 0; } } return 0; }
void CloseSkins( void ) { DmOpenRef dbRef; if ( NULL == resourceDBList ) return; dbRef = ListFirst( resourceDBList ); while ( dbRef != NULL ) { DmCloseDatabase( dbRef ); dbRef = ListNext( resourceDBList, dbRef ); } ListDelete( resourceDBList ); }
/*------------------------------------------------------------------ * delete entry from hash table *------------------------------------------------------------------*/ void HashDelete( Hash *hash, void *pItem ) { int h; if (!hash) return; h = hash->hashFunc(pItem,hash->buckets); if ((h < 0) || (h >= hash->buckets)) return; ListDelete(hash->bucket[h],pItem); }
void DelElem(SeqList *A, SeqList B) { int i, pos; DataType e; for(i = 0; i < B.length; i++) { if(GetElem(B, i + 1, &e)) /* 依次把B中的每个元素取出来 */ { if( (pos = LocateList(*A, e, compare )) >= 1) ListDelete(A, pos, &e ); } } }
void kraj(int sig) { RUNNING = 0; pthread_mutex_lock(&m_datagram_list); ListDelete(&datagram_list); pthread_mutex_unlock(&m_datagram_list); #ifdef DEBUG printf("Deleted all elements from datagram list\n"); #endif CloseUDPClient(upr_socket); #ifdef DEBUG printf("Client closed successfully\n"); #endif errx(USER_FAILURE, "User wants to quit!"); }
int main() { SqList L; L.length = 0; int e; //test code int i = 1; for(;i <= 20;i++) { if(ListInsert(&L,i,i)) { printf("%s","insert true Sq\n"); }else { printf("%s","insert false\n"); } } printf("%s","delete:"); for(i = 6;i <= 10;i++) { ListDelete(&L,i,&e); printf("delete pos %d = %d",i,e); } printf("%s","start:\n"); int index = 0; do { scanf("%d",&index); if(index < 0 || index > MAXSIZE) continue; if(GetElem(L,index,&e)) { printf("pos %d is %d.\n",index,e); }else { printf("%s","ERROR\n"); } }while(index != 99); return 1; }
//Sets the PROCESS alarm TimerTime TimerSetAlarm(TimerTime time) { TimerTime timeLeft; TimerQueue * queueHead; //First, remove previous alarm if(ProcCurrProcess->alarmPtr != NULL) { //Get time left queueHead = ListEntry(ProcCurrProcess->alarmPtr, TimerQueue, list); timeLeft = queueHead->endTime - currentTime; //Remove from list + free ListDelete(&queueHead->list); MemKFree(queueHead); //Wipe from process ProcCurrProcess->alarmPtr = NULL; } else { timeLeft = 0; } //If time is not 0, create new alarm if(time != 0) { //Create alarm queueHead = MemKAlloc(sizeof(TimerQueue)); queueHead->process = ProcCurrProcess; queueHead->endTime = time; //Add to list AddTimerToQueue(queueHead, &alarmQueueHead); //Add to process ProcCurrProcess->alarmPtr = &queueHead->list; } return timeLeft; }
#include "sqlist.cpp" /*假设线性表以顺序表表示*/ void main() { SqList *L; ElemType e; InitList(L); ListInsert(L,1,'a'); ListInsert(L,2,'c'); ListInsert(L,3,'a'); ListInsert(L,4,'d'); ListInsert(L,5,'b'); printf("ListLength(L)=%d\n",ListLength(L)); printf("ListEmpty(L)=%d\n",ListEmpty(L)); GetElem(L,3,e); printf("e=%c\n",e); printf("LocateElem(L,'a')=%d\n",LocateElem(L,'a')); ListInsert(L,4,'e'); DispList(L); ListDelete(L,3,e); DispList(L); DestroyList(L); }
void main() { LinkList L; ElemType e; int j; Status i; InitList(L); i = ListEmpty(L); printf("L是否空 i = %d (1:空 0:否)\n", i); ListInsert(L, 1, 3); ListInsert(L, 2, 5); i = GetElem(L, 1, e); j = ListLength(L); printf("L中的数据元素个数=%d, 第一个数据元素的值为%d.\n", j, e); printf("L中的数据元素依次为:"); ListTraverse(L, print); PriorElem(L, 5, e); printf("5前面的元素的值为%d.\n", e); NextElem(L, 3, e); printf("3后面的元素的值为%d.\n", e); printf("L是否空 %d(1:空 0:否)\n", ListEmpty(L)); j = LocateElem(L, 5, equal); if ( j ) printf("L的第%d个元素为5.\n", j); else printf("不存在值为5的元素.\n"); i = ListDelete(L, 2, e); printf("删除L的第2个元素:\n"); if ( i ) { printf("删除的元素值为%d, 现在L中的数据元素依次为", e); ListTraverse(L, print); } else printf("删除不成功!\n"); ClearList(L); printf("清空L后, L是否空:%d (1:空 0:否)\n", ListEmpty(L)); DestroyList(L); }
void * Thread_PlaySound_QuickTime(void *data) { int done = FALSE; fQTPlaying = TRUE; do { listOLD *pl; pthread_mutex_lock(&mutexQTAccess); /* give CPU time to QT to process all running movies */ MoviesTask(NULL, 0); /* check if there are any running movie left */ pl = &movielist; done = TRUE; do { listOLD *next = pl->plNext; if (pl->p != NULL) { Movie *movie = (Movie *) pl->p; if (IsMovieDone(*movie)) { DisposeMovie(*movie); free(movie); ListDelete(pl); } else done = FALSE; } pl = next; } while (pl != &movielist); pthread_mutex_unlock(&mutexQTAccess); } while (!done && fQTPlaying); fQTPlaying = FALSE; return NULL; }
static char *Concatenate( listOLD *pl ) { int cch = 0; char *sz, *pchDest, *pchSrc; for( pl = pl->plNext; pl->p; pl = pl->plNext ) cch += strlen( pl->p ); pchDest = sz = calloc(1, cch + 1 ); while( pl->plNext != pl ) { for( pchSrc = pl->plNext->p; ( *pchDest++ = *pchSrc++ ); ) ; pchDest--; free( pl->plNext->p ); ListDelete( pl->plNext ); } free( pl ); return sz; }