void RequestInit(TSession * const sessionP, TConn * const connectionP) { time_t nowtime; sessionP->validRequest = false; /* Don't have valid request yet */ time(&nowtime); sessionP->date = *gmtime(&nowtime); sessionP->conn = connectionP; sessionP->responseStarted = FALSE; sessionP->chunkedwrite = FALSE; sessionP->chunkedwritemode = FALSE; ListInit(&sessionP->cookies); ListInit(&sessionP->ranges); TableInit(&sessionP->request_headers); TableInit(&sessionP->response_headers); sessionP->status = 0; /* No status from handler yet */ StringAlloc(&(sessionP->header)); }
ParkingLot * InitParkingLot( FILE * mapconfig, int col, int row, int floors, int accesses ) { char *** matrix; int *vertices, *ramps; ParkingLot * parkinglot; vertices = (int*)malloc(sizeof(int)); VerifyMalloc( (Item) vertices ); ramps = (int*)malloc(sizeof(int)); VerifyMalloc( (Item) ramps ); parkinglot = (ParkingLot*) malloc( sizeof(ParkingLot) ); VerifyMalloc((Item) parkinglot); parkinglot->freespots = 0; matrix = MatrixInit(vertices, ramps, mapconfig, col, row, floors); /*Creates string cointaining the map - its a 3d string */ parkinglot->graphdecoder = GraphDecoderInit(matrix, col, row, floors, *vertices, &(parkinglot->freespots) ); /*Creates array cointaining the Decoder for the graph positions*/ parkinglot->g = GraphInit(*vertices, matrix, parkinglot->graphdecoder, col, row); parkinglot->accesseshead = InitAccesses(accesses, parkinglot->graphdecoder, *vertices); parkinglot->parkedcarshead = ListInit(); parkinglot->queuehead = ListInit(); /**PrintGraph(GetGraph(parkinglot), *vertices); */ /*prints the graph in the parkinglot */ FreeMatrix(matrix, col, row); free(vertices); free(ramps); return (parkinglot); }
List* ParseBuildList(char* s, Err* err){ List* L=NULL,*Lold=NULL; int i=0,iold=0; Str* S=NULL; Err* err2=ErrInit(); i=0; while ((s!=NULL)&&(i<strlen(s))){ iold=i; S=ParseLex(s, err,&i); if (S==NULL && i<strlen(s)){ err->pres=err2->pres; err->err=err2->err; myfree(err2); return NULL; } if (S==NULL && i>=strlen(s)){ break; } i=i; if (L==NULL) { L=ListInit(); Lold=L;} else { L->next=NULL; L->next=ListInit(); L=L->next;} ListPutDataStr(L,S->s); StrFree(S); /*printf("%s\n",S->s);*/ } myfree(err2->err); myfree(err2); return Lold; }
void RequestInit(TSession * const sessionP, TConn * const connectionP) { sessionP->validRequest = false; /* Don't have valid request yet */ time(&sessionP->date); sessionP->connP = connectionP; sessionP->responseStarted = FALSE; sessionP->chunkedwrite = FALSE; sessionP->chunkedwritemode = FALSE; sessionP->continueRequired = FALSE; ListInit(&sessionP->cookies); ListInit(&sessionP->ranges); TableInit(&sessionP->requestHeaderFields); TableInit(&sessionP->responseHeaderFields); sessionP->status = 0; /* No status from handler yet */ StringAlloc(&(sessionP->header)); }
heap_t *heapCreate (size_t heapSize) { heap_t *new_heap; sector_t *s0; new_heap = (heap_t*)malloc(sizeof(heap_t)); if(new_heap == NULL) { printf("Error during heap allocation\n"); exit(EXIT_FAILURE); } new_heap->empty=ListInit(); new_heap->full=ListInit(); new_heap->dim=heapSize; new_heap->base=malloc(heapSize);//memoria dello heap allocata if(new_heap->base == NULL) { printf("Error during base allocation\n"); exit(EXIT_FAILURE); } s0=(sector_t*)malloc(sizeof(sector_t)); if(s0==NULL) return NULL; s0->offset=(int)new_heap->base; s0->dimen=heapSize; new_heap->empty = OrderInsert(new_heap->empty,(void*)s0,NULL);//inserisco in empty la partizione intera return(new_heap); }
//////////////////////////////////////////////////// // 功能: // 输入: // 输出: // 返回: // 说明: //////////////////////////////////////////////////// void MediaSrvInit(void) { ListInit(&MediaObjList); ListInit(&MediaCallbackList); hMediaMutex = kMutexCreate(); JzSrvInit(); SaveMplayerVar(); }
// 说明:任务管理模块初始化 void TaskInit(void) { static uint32_t flag = FALSE; if (flag) { TEE_Printf("Task Module has been inited sometime before!\n"); return; } flag = TRUE; current_task = NULL; ListInit(&list_all_tasks); ListInit(&list_ready_tasks); ListInit(&list_suspud_tasks); }
MIMEType * MIMETypeCreate(void) { MIMEType * MIMETypeP; MALLOCVAR(MIMETypeP); if (MIMETypeP) { ListInit(&MIMETypeP->typeList); ListInit(&MIMETypeP->extList); PoolCreate(&MIMETypeP->pool, 1024); } return MIMETypeP; }
int main(void) { // 양방향 연결 리스트의 생성 및 초기화 /////// List list; int data; ListInit(&list); // 8개의 데이터 저장 /////// LInsert(&list, 1); LInsert(&list, 2); LInsert(&list, 3); LInsert(&list, 4); LInsert(&list, 5); LInsert(&list, 6); LInsert(&list, 7); LInsert(&list, 8); // 저장된 데이터의 조회 /////// if(LFirst(&list, &data)) { printf("%d ", data); while(LNext(&list, &data)) printf("%d ", data); while(LPrevious(&list, &data)) printf("%d ", data); printf("\n\n"); } return 0; }
/* initialize a list point - sets it as an empty list */ static FSTATUS PointInitList(Point *point, PointType type) { DLIST *pList; point->Type = POINT_TYPE_NONE; switch (type) { case POINT_TYPE_PORT_LIST: pList = &point->u.portList; break; case POINT_TYPE_NODE_LIST: pList = &point->u.nodeList; break; #if !defined(VXWORKS) || defined(BUILD_DMC) case POINT_TYPE_IOC_LIST: pList = &point->u.iocList; break; #endif default: ASSERT(0); return FINVALID_OPERATION; } ListInitState(pList); if (! ListInit(pList, MIN_LIST_ITEMS)) { fprintf(stderr, "%s: unable to allocate memory\n", g_Top_cmdname); return FINSUFFICIENT_MEMORY; } point->Type = type; return FSUCCESS; }
int main() { CommonDataStr commonDataStr; CommonDataStr *commonDataPtr = &commonDataStr; FILE *vertFilePtr; fopen_s(&vertFilePtr, VERTEX_FILE, "r"); if (vertFilePtr == NULL) { printf("Fatal Error: Unable to open %s File\n", VERTEX_FILE); return 1; } //Initialise the common data structure ListInit(&commonDataPtr->vertDataHead); commonDataPtr->numBits = 0; commonDataPtr->numVerts = 0; //Parse the vert file and create the vert data list ParseVertFile(vertFilePtr, commonDataPtr); //Decompress the bitstream file and find RMS error DecompressFromBitStream(commonDataPtr); //Free the vert data FreeVertData(commonDataPtr); fclose(vertFilePtr); return 0; }
BOOL ReadMacro(HPTR hpBuf, LPLIST lpMacroList, BOOL fReadFirstPacketOnly) /***********************************************************************/ { LPTSTR lpCommand; MACRO_FILE_HANDLE fh; LPCMDPKT lpCmdPkt; BOOL fError; // zero out the list ListInit(lpMacroList); // Allocate a buffer to read the commands into if (!(lpCommand = (LPTSTR)Alloc(MAX_CMD_LEN))) { Message(IDS_EMEMALLOC); return(FALSE); } while (lpCmdPkt = ReadPacket(&hpBuf, lpCommand, &fError)) { ListAddTail(lpMacroList, lpCmdPkt); if (fReadFirstPacketOnly) break; } FreeUp(lpCommand); if (fError) { DestroyPacketList(lpMacroList); return(FALSE); } return(TRUE); }
void TestIterator() { List* list = ListInit(); /* Prepare the initial elements. */ CU_ASSERT(list->push_back(list, (void*)(intptr_t)1) == true); CU_ASSERT(list->push_back(list, (void*)(intptr_t)2) == true); CU_ASSERT(list->push_back(list, (void*)(intptr_t)3) == true); CU_ASSERT(list->push_back(list, (void*)(intptr_t)4) == true); /* Iterate through the list. */ void* element; int check = 1; list->first(list, false); while (list->next(list, &element)) { CU_ASSERT_EQUAL((int)(intptr_t)element, check); ++check; } /* Iterate through the list in reversed order. */ check = 4; list->first(list, true); while (list->reverse_next(list, &element)) { CU_ASSERT_EQUAL((int)(intptr_t)element, check); --check; } ListDeinit(list); }
ListNode * InitAccesses(int accesses, Array decoder, int vertices) { int i, *index, counter = 0; char type; ListNode* accesseshead = ListInit(); for(i = 0; i < vertices; i++) /*Goes through every vertice in the decoder to see if it is or not an access */ { type = GetIP_Type(i, decoder); if( type == 'R' || type == 'C' || type == 'H' || type == 'E' || type == 'L' ) /*If it is an access */ { index = (int*) malloc( sizeof(int) ); VerifyMalloc((Item) index); *index = i; counter++; accesseshead = AddNodeToListHead(accesseshead, (Item) index); } } if(counter != accesses) { printf("Error. Number of read accesses doesnt match info from file."); exit(0); } return accesseshead; }
List *ListCopy(List *in, int deep) { ListItem *item, *outitem; List *out; out = ListInit(); item = in->first; while (item != NULL) { outitem = (ListItem *)lt_malloc_incontext(sizeof(ListItem), out->memory_context); outitem->prev = out->last; outitem->next = NULL; outitem->DataSize = item->DataSize; if (item->copyable != 0) { outitem->data = (void *)lt_malloc_incontext(outitem->DataSize, out->memory_context); memcpy(outitem->data, item->data, outitem->DataSize); } else { if ((deep!=0)&&(item->DataType == DATATYPE_LIST)) outitem->data = ListCopy((List *)item->data,1); else if ((deep!=0)&&(item->DataType == DATATYPE_DICT)) outitem->data = DictCopy((Dict *)item->data,1); else outitem->data = item->data ; } outitem->copyable = item->copyable; outitem->DataType = item->DataType; if (out->first == NULL) out->first = outitem; if (out->last != NULL) out->last->next = outitem; out->last = outitem; out->length++; item = item->next; } return out; }
void TestInsert() { List* list = ListInit(); /* Insert elements to the specified indexes. */ CU_ASSERT(list->insert(list, 1, (void*)(intptr_t)1) == false); CU_ASSERT(list->insert(list, 0, (void*)(intptr_t)1) == true); CU_ASSERT(list->insert(list, 1, (void*)(intptr_t)4) == true); CU_ASSERT(list->insert(list, 1, (void*)(intptr_t)2) == true); CU_ASSERT(list->insert(list, 2, (void*)(intptr_t)3) == true); CU_ASSERT(list->insert(list, 0, (void*)(intptr_t)0) == true); /* Check element insertion sequence. */ void* element; CU_ASSERT(list->get_front(list, &element) == true); CU_ASSERT_EQUAL(element, (void*)(intptr_t)0); CU_ASSERT(list->get_back(list, &element) == true); CU_ASSERT_EQUAL(element, (void*)(intptr_t)4); CU_ASSERT(list->get_at(list, 0, &element) == true); CU_ASSERT_EQUAL(element, (void*)(intptr_t)0); CU_ASSERT(list->get_at(list, 1, &element) == true); CU_ASSERT_EQUAL(element, (void*)(intptr_t)1); CU_ASSERT(list->get_at(list, 2, &element) == true); CU_ASSERT_EQUAL(element, (void*)(intptr_t)2); CU_ASSERT(list->get_at(list, 3, &element) == true); CU_ASSERT_EQUAL(element, (void*)(intptr_t)3); CU_ASSERT(list->get_at(list, 4, &element) == true); CU_ASSERT_EQUAL(element, (void*)(intptr_t)4); CU_ASSERT_EQUAL(list->size(list), 5); ListDeinit(list); }
void TestReverse() { List* list = ListInit(); /* Prepare the initial elements. */ CU_ASSERT(list->push_back(list, (void*)(intptr_t)1) == true); CU_ASSERT(list->push_back(list, (void*)(intptr_t)2) == true); CU_ASSERT(list->push_back(list, (void*)(intptr_t)3) == true); CU_ASSERT(list->push_back(list, (void*)(intptr_t)4) == true); list->reverse(list); /* Check the reversed element sequence. */ void* element; CU_ASSERT(list->get_at(list, 0, &element) == true); CU_ASSERT_EQUAL(element, (void*)(intptr_t)4); CU_ASSERT(list->get_at(list, 1, &element) == true); CU_ASSERT_EQUAL(element, (void*)(intptr_t)3); CU_ASSERT(list->get_at(list, 2, &element) == true); CU_ASSERT_EQUAL(element, (void*)(intptr_t)2); CU_ASSERT(list->get_at(list, 3, &element) == true); CU_ASSERT_EQUAL(element, (void*)(intptr_t)1); ListDeinit(list); }
//////////////////////////////////////////////////// // 功能: // 输入: // 输出: // 返回: // 说明: //////////////////////////////////////////////////// int MediaSrvRegistCallback(int type, DWORD device, PMEDIA_CALLBACK callback) { PLIST n; PLIST head; PCALLBACK_LINK check; PCALLBACK_LINK link; // 申请节点,并初始化 link = kmalloc(sizeof(CALLBACK_LINK)); if(link == NULL) return -1; kmemcpy(&link->Callback, callback, sizeof(MEDIA_CALLBACK)); link->Type = type; link->Device = device; ListInit(&link->Link); // 检查设备是否已经注册 head = &MediaCallbackList; for(n=ListFirst(head); n!=head; n=ListNext(n)) { check = ListEntry(n, CALLBACK_LINK, Link); if(&check->Callback == callback) { kfree(link); return -1; } } ListInsert(&MediaCallbackList, &link->Link); return 0; }
int main() { DPoint _PFir; DPoint _PSec; DPoint _PAim; DPoint _pCro; _PFir._PointX=0.0; _PFir._PointY=0.0; _PSec._PointX=100.0; _PSec._PointY=0.0; _PAim._PointX=20.0; _PAim._PointY=60.0; CalcuVertical(_PFir,_PSec, _PAim,&_pCro); printf("%.6lf, %.6lf", _pCro._PointX, _pCro._PointY); printf("%.6lf",CalcuDis(_PFir,_PSec,_PAim)); //////////////////////////////////////// SqList lo; ListInit(&lo); DPoint _dPValue; DPoint _dPIValue; _dPValue._PointX = 100.0; _dPValue._PointY = 100.0; _dPIValue._PointX = 300.0; _dPIValue._PointY = 300.0; for (size_t _i=0;_i<3;_i++) { ListInsert(&lo,1,_dPValue); } ListInsert(&lo,2,_dPIValue); printf("%.6lf,%.6lf",lo._nArray[0]._PointX,lo._nArray[0]._PointX); ////////////////////////////////////// // vector<vector<CPoint>> _vecPOINT; // vector<CPoint> _vecIn; // CPoint _ptFir; // CPoint _ptIn; // _ptIn.SetPoint(300,300); // _ptFir.SetPoint(100,100); // // _vecIn.push_back(_ptFir); // for (size_t _i=0; _i<5;_i++) // { // _vecIn.push_back(_ptFir); //_vecPOINT.push_back(_vecIn); // } // // _vecPOINT.push_back(_vecIn); // // _vecPOINT[0].insert(_vecPOINT[0].begin()+1,_ptIn); /////////////////////////////////////// return 0; }
/*-----------------------------------------------------------------------------* * Unit tests relevant to complex data maintenance * *-----------------------------------------------------------------------------*/ void TestObjectInsert() { char* nums[SIZE_MID_TEST]; char buf[SIZE_TXT_BUFF]; int idx = 0; while (idx < SIZE_MID_TEST) { snprintf(buf, SIZE_TXT_BUFF, "%d", idx); nums[idx] = strdup((const char*)buf); ++idx; } List* list = ListInit(); list->set_clean(list, CleanElement); /* Push the elements ranging from 1536 to 2047 to the list tail. */ idx = SIZE_MID_TEST - SIZE_SML_TEST; while (idx < SIZE_MID_TEST) { CU_ASSERT(list->push_back(list, strdup(nums[idx])) == true); ++idx; } /* Push the elements ranging from 0 to 511 to the list head. */ idx = SIZE_SML_TEST - 1; while (idx >= 0) { CU_ASSERT(list->push_front(list, strdup(nums[idx])) == true); --idx; } /* Insert the elements ranging from 512 to 1535. */ idx = SIZE_SML_TEST; int bnd = SIZE_MID_TEST - SIZE_SML_TEST; while (idx < bnd) { CU_ASSERT(list->insert(list, idx, strdup(nums[idx])) == true); ++idx; } /* Check the element sequence. */ void* element; CU_ASSERT(list->get_front(list, &element) == true); CU_ASSERT(strcmp((char*)element, nums[0]) == 0); CU_ASSERT(list->get_back(list, &element) == true); CU_ASSERT(strcmp((char*)element, nums[SIZE_MID_TEST - 1]) == 0); idx = 0; while (idx < SIZE_MID_TEST) { CU_ASSERT(list->get_at(list, idx, &element) == true); CU_ASSERT(strcmp((char*)element, nums[idx]) == 0); ++idx; } ListDeinit(list); idx = 0; while (idx < SIZE_MID_TEST) { free(nums[idx]); ++idx; } }
int main(int argc, char *args[]) { char *buffer = (char *)malloc(MAX_LINE_LEN);; char *result = (char *)malloc(MAX_LINE_LEN);; int number; int dwnum; dwnum = GetPrice(); if(dwnum != 0) { return dwnum; } list_t *L = ListInit(); if(L == NULL) { return ERRNO_NULL_POINTER; } while(fgets(buffer, MAX_LINE_LEN, stdin)) { number = 0; memset(result, 0, MAX_LINE_LEN); dwnum = ParseLine(buffer, result, &number); if(dwnum == 0) { item_t* curnode; if((curnode = ListIsNodeInListById(L, result)) != NULL) { curnode->count += number; continue; } item_t * node = ItemMakeitem(result, number); if(node == NULL) { return ERRNO_MAKEITEM_FAIL; } dwnum = ListPushBack(L, (void*) node); if(dwnum != 0) { return ERRNO_LISTPUSHBACK_FAIL; } } } dwnum = CalculateSum(L); if(dwnum != 0) { return ERRNO_CALCULATESUM_FAIL; } ListFree(L); ListFree(my_price); free(buffer); free(result); return 0; }
/************************************************************************ * Function: TimerThreadInit * * Description: * Initializes and starts timer thread. * * Parameters: * timer - valid timer thread pointer. * tp - valid thread pool to use. Must be * started. Must be valid for lifetime * of timer. Timer must be shutdown * BEFORE thread pool. * Return: * 0 on success, nonzero on failure * Returns error from ThreadPoolAddPersistent if failure. ************************************************************************/ int TimerThreadInit( TimerThread * timer, ThreadPool * tp ) { int rc = 0; ThreadPoolJob timerThreadWorker; assert( timer != NULL ); assert( tp != NULL ); if( ( timer == NULL ) || ( tp == NULL ) ) { return EINVAL; } rc += ithread_mutex_init( &timer->mutex, NULL ); assert( rc == 0 ); rc += ithread_mutex_lock( &timer->mutex ); assert( rc == 0 ); rc += ithread_cond_init( &timer->condition, NULL ); assert( rc == 0 ); rc += FreeListInit( &timer->freeEvents, sizeof( TimerEvent ), 100 ); assert( rc == 0 ); timer->shutdown = 0; timer->tp = tp; timer->lastEventId = 0; rc += ListInit( &timer->eventQ, NULL, NULL ); assert( rc == 0 ); if( rc != 0 ) { rc = EAGAIN; } else { TPJobInit( &timerThreadWorker, TimerThreadWorker, timer ); TPJobSetPriority( &timerThreadWorker, HIGH_PRIORITY ); rc = ThreadPoolAddPersistent( tp, &timerThreadWorker, NULL ); } ithread_mutex_unlock( &timer->mutex ); if( rc != 0 ) { ithread_cond_destroy( &timer->condition ); ithread_mutex_destroy( &timer->mutex ); FreeListDestroy( &timer->freeEvents ); ListDestroy( &timer->eventQ, 0 ); } return rc; }
BOOL ReadMacro(LPTSTR lpFileName, LPLIST lpMacroList, BOOL fReadFirstPacketOnly) /***********************************************************************/ { LPTSTR lpCommand; MACRO_FILE_HANDLE fh; LPCMDPKT lpCmdPkt; BOOL fError; FNAME OEMName; // zero out the list ListInit(lpMacroList); // Open the macro file #ifdef BUFFERED_IO AnsiToOem(lpFileName, OEMName); fh = fopen(OEMName, _T("rb")); if (fh == NULL) #else fh = FileOpen(lpFileName, FO_READ); if (fh == MACRO_FILE_HANDLE_INVALID) #endif { Message(IDS_EOPEN, lpFileName); return(FALSE); } // Allocate a buffer to read the commands into if (!(lpCommand = (LPTSTR)Alloc(MAX_CMD_LEN))) { #ifdef BUFFERED_IO fclose(fh); #else FileClose(fh); #endif Message(IDS_EMEMALLOC); return(FALSE); } AstralCursor(IDC_WAIT); while (lpCmdPkt = ReadPacket(fh, lpCommand, &fError)) { ListAddTail(lpMacroList, lpCmdPkt); if (fReadFirstPacketOnly) break; } AstralCursor(NULL); FreeUp(lpCommand); #ifdef BUFFERED_IO fclose(fh); #else FileClose(fh); #endif if (fError) { DestroyPacketList(lpMacroList); return(FALSE); } return(TRUE); }
/*------------------------------------------------------------------------ --------------------------- Initialize Scheduler ------------------------- ------------------------------------------------------------------------*/ int InitScheduler(floDefPtr flo) { /* plug in the DDXIE scheduler vector */ flo->schedVec = &schedulerVec; /* init the scheduler ready-list */ ListInit(&flo->floTex->schedHead); return(TRUE); } /* end InitScheduler */
/****************************************************** * This function Initialises the common data structure * with default values. ********************************************************/ void InitCommonData(CommonDataStr *commonDataPtr) { commonDataPtr->minX = DBL_MAX; commonDataPtr->minY = DBL_MAX; commonDataPtr->minZ = DBL_MAX; commonDataPtr->maxX = DBL_MIN; commonDataPtr->maxY = DBL_MIN; commonDataPtr->maxZ = DBL_MIN; ListInit(&commonDataPtr->vertDataHead); }
//////////////////////////////////////////////////// // 功能: 为音频任务申请并初始化节点 // 输入: // 输出: // 返回: // 说明: //////////////////////////////////////////////////// static PMEDIA_OBJECT MediaSrvObjCreate(void *media, char *name, int type) { PMEDIA_OBJECT obj; // 输入参数检查 if(!media) return NULL; // 申请节点,并初始化 obj = kmalloc(sizeof(MEDIA_OBJECT)); if(obj == NULL) return NULL; kmemset(obj, 0x00, sizeof(MEDIA_OBJECT)); ListInit(&obj->Link); if(MediaSrvGetCallback(type, &obj->Cb) < 0) { kdebug(mod_media, PRINT_ERROR, "MediaSrvGetCallback error\n"); kfree(obj); return NULL; } if(((PMEDIA_TASK)media)->ExterdType == 1 && JzSrvUseMplayer() < 0) { kdebug(mod_media, PRINT_ERROR, "MediaSrvGetCallback error: mplayer already exist\n"); kfree(obj); return NULL; } // 创建媒体任务 obj->Media = obj->Cb.MediaCreate(media); if(obj->Media == NULL) { kfree(obj); return NULL; } // 保存媒体名称 if(name) { obj->MediaInfo = kmalloc(kstrlen(name)+1); if(obj->MediaInfo) kstrcpy(obj->MediaInfo, name); } // 设置媒体任务 #if defined(STC_EXP) obj->hTask = sTaskSelf(); #else obj->hTask = TaskSelf(); #endif // 返回媒体对象 return obj; }
/*-----------------------------------------------------------------------------* * Unit tests relevant to basic structure verification * *-----------------------------------------------------------------------------*/ void TestNewDelete() { List* list; CU_ASSERT((list = ListInit()) != NULL); /* Enlarge the list size to test the destructor. */ unsigned i; for (i = 0 ; i < SIZE_SML_TEST ; ++i) CU_ASSERT(list->push_back(list, (void*)(intptr_t)i) == true); ListDeinit(list); }
int main(void) { // List의 생성 및 초기화 //////////// List list; int data; ListInit(&list); SetSortRule(&list, WhoIsPrecede); // 5개의 데이터 저장 /////////////// LInsert(&list, 11); LInsert(&list, 11); LInsert(&list, 22); LInsert(&list, 22); LInsert(&list, 33); // 저장된 데이터의 전체 출력 //////////// printf("현재 데이터의 수: %d \n", LCount(&list)); if(LFirst(&list, &data)) { printf("%d ", data); while(LNext(&list, &data)) printf("%d ", data); } printf("\n\n"); // 숫자 22을 검색하여 모두 삭제 //////////// if(LFirst(&list, &data)) { if(data == 22) LRemove(&list); while(LNext(&list, &data)) { if(data == 22) LRemove(&list); } } // 삭제 후 저장된 데이터 전체 출력 //////////// printf("현재 데이터의 수: %d \n", LCount(&list)); if(LFirst(&list, &data)) { printf("%d ", data); while(LNext(&list, &data)) printf("%d ", data); } printf("\n\n"); return 0; }
void GraphInit(ALGraph * pg, int nv) { int i; pg->adjList = (List *)malloc(sizeof(List)*nv); pg->numV = nv; pg->numE = 0; for(i=0; i<nv; i++){ ListInit(&(pg->adjList[i])); SetSortRule(&(pg->adjList[i]), WhoIsPrecede); } }
bool TestListInit(List *list, ListType type) { if (!ListInit(list, type)) { sprintf(error, "ListInit failed"); return false; } if (!ListEmpty(list)) { sprintf(error, "List *is not empty after init"); return false; } return true; }