int main(int argc, const char * argv[]) { // insert code here... printf("Hello, World!\n"); LIST Listheader ={0,NULL}; LIST *list = &Listheader; List_Insert(list, 1, 11); List_Insert(list, 2, 22); List_Insert(list, 3, 33); List_Insert(list, 4, 44); printf("0:%d",list->value); printf("2:%d",List_FindAccordingNumber(list, 2)->value); return 0; }
void CSmileyString::AddListeningToIcon(SHORTDATA *dat, TCHAR *szText) { iMaxSmileyHeight = 0; DestroySmileyList(); if (szText == NULL) return; int text_size = (int)mir_tstrlen(szText); plText = List_Create(0, 1); // Add Icon { ClcContactTextPiece *piece = (ClcContactTextPiece *)mir_alloc(sizeof(ClcContactTextPiece)); piece->type = TEXT_PIECE_TYPE_SMILEY; piece->len = 0; piece->smiley = g_hListeningToIcon; piece->smiley_width = 16; piece->smiley_height = 16; ICONINFO icon; if (GetIconInfo(piece->smiley, &icon)) { BITMAP bm; if (GetObject(icon.hbmColor, sizeof(BITMAP), &bm)) { piece->smiley_width = bm.bmWidth; piece->smiley_height = bm.bmHeight; } DeleteObject(icon.hbmMask); DeleteObject(icon.hbmColor); } dat->text_smiley_height = max(piece->smiley_height, dat->text_smiley_height); iMaxSmileyHeight = max(piece->smiley_height, iMaxSmileyHeight); List_Insert(plText, piece, plText->realCount); } // Add text { ClcContactTextPiece *piece = (ClcContactTextPiece *)mir_alloc(sizeof(ClcContactTextPiece)); piece->type = TEXT_PIECE_TYPE_TEXT; piece->start_pos = 0; piece->len = text_size; List_Insert(plText, piece, plText->realCount); } }
ClcCacheEntry *GetCLCFullCacheEntry(struct ClcData *dat,MCONTACT hContact) { if (hContact == 0) return NULL; ClcCacheEntry dnce; dnce.hContact = hContact; ClcCacheEntry *pdnce = (ClcCacheEntry*)List_Find(&dat->lCLCContactsCache,&dnce); if (pdnce == NULL) { pdnce = (ClcCacheEntry*)mir_calloc(sizeof(ClcCacheEntry)); pdnce->hContact = hContact; int idx; List_GetIndex(&dat->lCLCContactsCache,pdnce,&idx); List_Insert(&dat->lCLCContactsCache,pdnce,idx); ClcCacheEntry *pdnce2 = (ClcCacheEntry*)List_Find(&dat->lCLCContactsCache,&dnce);//for check if (pdnce2->hContact != pdnce->hContact) return NULL; if (pdnce2 != pdnce) return NULL; } return (pdnce); }
// thread tolerant, if updating id dont pass proto, if updating proto dont pass id void contactDir_Contact_Add(contactDir * cd, HANDLE hContact, char * proto, char * id) { // if a contact is gonna exist anywhere it's going to be in the ->protoCache which has a key of hContact // if id is not null then the contact should be indexed via the ->contactCache instead if ( id == NULL ) { int index = 0; contactEntry e; e.hContact=hContact; e.proto = proto; e.id = ""; EnterCriticalSection(&cd->csLock); if ( List_GetIndex(&cd->protoCache, &e, &index) ) { contactEntry * p = cd->protoCache.items[index]; // this hContact is in the cache, protcol changing? p->proto = contactDir_Proto_Add(cd, proto); // just replace the old pointer } else { contactEntry * p = 0; // this hContact isn't in the cache, add it p = HeapAlloc(hCacheHeap, HEAP_NO_SERIALIZE, sizeof(contactEntry)); p->proto = contactDir_Proto_Add(cd, proto); p->id = 0; p->hContact = hContact; // add it List_Insert(&cd->protoCache, p, index); } LeaveCriticalSection(&cd->csLock); } else { // this contact HAS to be in ->protoCache since it was added during startup // need to find the contactEntry* that should already exist for it } //if }
void PStack_Add_Page(PStack *pstack) { PStack_Page *page = new PStack_Page; List_Insert(&(pstack->page_list), &(page->list_head)); page->size = PStack_Page_Size; page->hwm = 0; page->page = new char[PStack_Page_Size]; }
int main(void) { Sqlist lc,ld,lb,la; int e,locale,pos,elem; init_list(&lc); CreateList(&lc); print(lc); printf("Please enter the elem your want to find:\n"); scanf("%d",&e); locale = location(&lc, e); printf("the location of elem is %d\n",locale); printf("Please enter the insert position and the elem:\n"); scanf("%d%d",&pos,&elem); List_Insert(&lc,pos,elem); printf("after insert elem ,the Sqlist is:\n"); print(lc); printf("Please enter the insert position and the elem:\n"); scanf("%d%d",&pos,&elem); List_Del(&lc,pos,elem); printf("after delete elem ,the Sqlist is:\n"); print(lc); init_list(&ld); init_list(&la); CreateList(&la); init_list(&lb); CreateList(&lb); Combine(la,lb,&ld); print(ld); return 0; }
void InitDisplayNameCache(SortedList *list) { int i; HANDLE hContact; memset(list,0,sizeof(SortedList)); list->dumpFunc =DumpElem; list->sortFunc=handleCompare; list->sortQsortFunc=handleQsortCompare; list->increment=CallService(MS_DB_CONTACT_GETCOUNT,0,0)+1; hContact=(HANDLE)CallService(MS_DB_CONTACT_FINDFIRST,0,0); i=0; while (hContact!=0) { displayNameCacheEntry *pdnce; pdnce=mir_calloc(1,sizeof(displayNameCacheEntry)); pdnce->hContact=hContact; InvalidateDisplayNameCacheEntryByPDNE(hContact,pdnce,0); List_Insert(list,pdnce,i); hContact=(HANDLE)CallService(MS_DB_CONTACT_FINDNEXT,(WPARAM)hContact,0); i++; } //List_Dump(list); List_Sort(list); // List_Dump(list); }
void test(){ /* 测试链表函数 测试结果:全部函数运行通过 */ List A; int a[]={1,2,3,4}; List B; int b[]={5,6,7,8,9}; List_Init(&A); List_Init(&B); List_creat(&A,a,4); List_creat(&B,b,5); printf("\nA:"); List_printf(&A); printf("\nB:"); List_printf(&B); List_Insert(&A,1,2); printf("\nA:"); List_printf(&A); printf("\nA length:%d",List_getLength(&A)); List_clear(&B); printf("\nB:"); List_printf(&B); List_destroy(&B); }
void* pthread_list_insert(void* arg) { list_insert_arg *arg_struct = arg; List_Insert(arg_struct->list, arg_struct->element, arg_struct->key); return NULL; }
List * List_Insert(List * head, char * str){ if (head == NULL) { return List_createNode(str); } head -> next = List_Insert(head -> next, str); return head; }
Node * Shell_Sort(Node *list) { long Size; //store the size of the integer list Size = findSize(list); //find the size int q = largest_index(3, Size); //find the largest value for q less than size long j, l; int count1; Node * head = list; int pow1, pow2, k; for (pow1 = q; pow1 >= 0; pow1--) { for (pow2 = pow1; pow2 >= 0 ; pow2--) { Node * cur = head; k = power(3, pow2) * power(2, pow1 - pow2); //use this formula to calculate the sequence elements for (j = 1; j <= (Size - k); j++) { List * dhead = NULL; dhead = List_Insert(dhead, cur); //insert starting from the first j'th value Node * tmp1 = cur; for (l = j + k; l <= Size; l = l + k) { //printf("\nj+k=%ld\n", l); count1 = 0; while (count1 != k) { tmp1 = tmp1 -> next; //keep on iterating till you reach the correct node count1++; } dhead = List_Insert(dhead, tmp1); //insert node into the sublist } Insertion_Sort(dhead); //implement insertion sort cur = cur -> next; //make current as the next node while (dhead != NULL) //free memory due to each sublist before the next iteration { List * tmp = dhead; dhead = dhead -> next; free(tmp); } } } } return head; //return the list of integers that has been sorted }
MIR_CORE_DLL(int) List_InsertPtr(SortedList* list, void* p) { if (p == NULL) return -1; int idx = list->realCount; List_GetIndex(list, p, &idx); return List_Insert(list, p, idx); }
int main(void) { List* list = List_Create(); int i = 0; int j = 1; int k = 2; List_Insert(list, &i, 0); List_Insert(list, &j, 1); List_Insert(list, &k, 2); List_Clear(list); List_Destroy(list); return 0; }
unsigned int PStack_List_Add_PStack() { static unsigned int id = 0; PStack *pstack = new PStack; id = id + 1; List_Insert(&PStack_List, &(pstack->list_head)); List_Initial(&(pstack->page_list)); pstack->stack_id = id; return id; }
int Car_Insert(int carnum) { int c = List_GetIndex(CarList, carnum); if (c < 0 && CarList->length != carnum) { return FALSE; } PTCar car = Car_Create(); PTListItem pli = List_Insert(CarList, (void *) car, carnum); pli->destroy_func = (TItem_Destroy_Func) Car_Destroy; return TRUE; }
int fnAddItemToGroup(ClcGroup *group, int iAboveItem) { ClcContact* newItem = cli.pfnCreateClcContact(); newItem->type = CLCIT_DIVIDER; newItem->flags = 0; newItem->szText[0] = '\0'; memset(newItem->iExtraImage, 0xFF, sizeof(newItem->iExtraImage)); List_Insert((SortedList*)&group->cl, newItem, iAboveItem); return iAboveItem; }
MIR_CORE_DLL(void) List_ObjCopy(SortedList* s, SortedList* d, size_t itemSize) { d->increment = s->increment; d->sortFunc = s->sortFunc; for (int i = 0; i < s->realCount; i++) { void* item = new char[itemSize]; memcpy(item, s->items[i], itemSize); List_Insert(d, item, i); } }
static void addItem(int color, List_Links *list) { Item *i; i = (Item *)malloc(sizeof(Item)); assert(i); List_Init((List_Links *)i); i->color = color; List_Insert((List_Links *)i, LIST_ATREAR(list)); assert(((Item *)List_Last(list))->color == color); return; }
void ListSuite_TestInsert( ListSuiteData* data ) { Index idx; /* Initially, insert at the end */ for( idx = 0; idx < NUM_ITEMS/2; idx++ ) { List_Insert( data->list, idx, &data->arrayData[idx] ); } /* Then insert the rest from the half-way point */ for( idx = NUM_ITEMS/2; idx < NUM_ITEMS; idx++ ) { List_Insert( data->list, NUM_ITEMS/2, &data->arrayData[idx] ); } pcu_check_true( data->list->nItems == NUM_ITEMS ); for( idx = 0; idx < NUM_ITEMS/2; idx++ ) { pcu_check_true( *(int*)List_GetItem( data->list, idx ) == idx ); } for( idx = NUM_ITEMS/2; idx < NUM_ITEMS; idx++ ) { pcu_check_true( *(int*)List_GetItem( data->list, idx ) == ((NUM_ITEMS-1) - (idx - NUM_ITEMS/2)) ); } }
int main() { int element = 255; unsigned int key = 127; list_t lst; List_Init(&lst); List_Insert(&lst, (void*)&element, key); List_Delete(&lst, key); void *val = List_Lookup(&lst, key); if (!val) return 0; else return -1; }
int Axle_Insert(int carnum, int i) { PTCar car = Car_Get(carnum); if (car == NULL) { return FALSE; } int c = List_GetIndex(car->axles, i); if (c < 0 && car->axles->length != i) { return FALSE; } PTAxle axle = Axle_Create(); PTListItem pli = List_Insert(car->axles, (void *) axle, i); pli->destroy_func = (TItem_Destroy_Func) Axle_Destroy; return TRUE; }
// cache the protocol string so that its not allocated per contact but shared char * contactDir_Proto_Add(contactDir * cd, char * proto) { int index = 0 ; char * szCache = 0; EnterCriticalSection(&cd->csLock); if ( List_GetIndex(&cd->protoNameCache, proto, &index) ) szCache = cd->protoNameCache.items[index]; else { szCache = HeapAlloc(hCacheHeap, HEAP_NO_SERIALIZE, strlen(proto)+1); strcpy(szCache, proto); List_Insert(&cd->protoNameCache, szCache, index); } LeaveCriticalSection(&cd->csLock); return szCache; }
//------------------------------------------------------------------- EPOPEIA_API int FunctionTable_Register(TFunctionId Id) { ASSERT(g_Initialized); ASSERT(Id != NULL); List_Reset(g_FunctionList); List_Goto(g_FunctionList, Id); if(!List_EOF(g_FunctionList)) { // Existe una funcion con el mismo nombre! DEBUG_msg("Ya existe una funcion con el mismo nombre!"); return 1; } List_Insert(g_FunctionList, Id); return 0; }
INT_PTR registerToken(WPARAM wParam, LPARAM lParam) { DWORD hash; int idx; TOKENREGISTEREX *newVr = (TOKENREGISTEREX*)lParam; if (newVr == NULL || newVr->szTokenString == NULL || newVr->cbSize <= 0) return -1; if (newVr->flags & TRF_TCHAR) { deRegisterToken(newVr->tszTokenString); hash = NameHashFunction(newVr->tszTokenString); } else { WCHAR *wtoken = mir_a2t(newVr->szTokenString); deRegisterToken(wtoken); hash = NameHashFunction(wtoken); mir_free(wtoken); } TokenRegisterEntry *tre = (TokenRegisterEntry*)mir_alloc(sizeof(TokenRegisterEntry)); if (tre == NULL) return -1; memcpy(&tre->tr, newVr, newVr->cbSize); tre->nameHash = hash; if (!mir_tstrcmp(newVr->tszTokenString, _T("alias"))) log_debugA("alias"); if (!(newVr->flags & TRF_PARSEFUNC) && newVr->szService != NULL) tre->tr.szService = mir_strdup(newVr->szService); if (newVr->flags & TRF_TCHAR) tre->tr.tszTokenString = mir_tstrdup(newVr->tszTokenString); else tre->tr.tszTokenString = mir_a2t(newVr->szTokenString); if (newVr->szHelpText != NULL) tre->tr.szHelpText = mir_strdup(newVr->szHelpText); if ((newVr->flags & TRF_CLEANUP) && !(newVr->flags & TRF_CLEANUPFUNC) && newVr->szCleanupService != NULL) tre->tr.szCleanupService = mir_strdup(newVr->szCleanupService); mir_cslock lck(csRegister); List_GetIndex((SortedList*)&tokens, tre, &idx); List_Insert((SortedList*)&tokens, tre, idx); return 0; }
void MF_Insert_Vertex_R2(MFace_ptr f, MVertex_ptr nuv, MVertex_ptr b4v) { MFace_Adj_R2 *adj; adj = (MFace_Adj_R2 *) f->adj; if (adj->fvertices == NULL) adj->fvertices = List_New(4); #ifdef DEBUG if (MF_Mesh(f) != MV_Mesh(nuv)) MSTK_Report("MF_Replace_Vertex_R2", "Face and Vertex are not from the same mesh", MSTK_FATAL); #endif List_Insert(adj->fvertices,nuv,b4v); }
void InitDisplayNameCache(SortedList *list) { int i, idx; memset(list,0,sizeof(SortedList)); list->sortFunc = (FSortFunc)handleCompare; list->increment = CallService(MS_DB_CONTACT_GETCOUNT,0,0)+1; i = 0; for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { ClcCacheEntry *pdnce = (ClcCacheEntry *)mir_calloc(sizeof(ClcCacheEntry)); pdnce->hContact = hContact; InvalidateDisplayNameCacheEntryByPDNE(hContact,pdnce,0); List_GetIndex(list,pdnce,&idx); List_Insert(list,pdnce,idx); i++; } }
void CSmileyString::_CopySmileyList(SortedList *plInput) { if (!plInput || plInput->realCount == 0) return; plText = List_Create(0, 1); for (int i = 0; i < plInput->realCount; i++) { ClcContactTextPiece *pieceFrom = (ClcContactTextPiece *)plInput->items[i]; if (pieceFrom != nullptr) { ClcContactTextPiece *piece = (ClcContactTextPiece *)mir_alloc(sizeof(ClcContactTextPiece)); *piece = *pieceFrom; if (pieceFrom->type == TEXT_PIECE_TYPE_SMILEY) piece->smiley = CopyIcon(pieceFrom->smiley); List_Insert(plText, piece, plText->realCount); } } }
int main() { Node * head_ptr; head_ptr = List_User_Init(); List_Traversal(head_ptr); List_Insert(head_ptr,7); List_Insertn(head_ptr,2,7); List_Traversal(head_ptr); List_DeleteNode(head_ptr); List_DeleteNthNode(head_ptr,3); List_Traversal(head_ptr); head_ptr = remove_if_basic(head_ptr,fun1); remove_if(&head_ptr,fun2); List_Traversal(head_ptr); List_Delete(head_ptr); }
/* * ---------------------------------------------------------------------------- * * VmStackInit -- * * Allocate and initialize the stack stuff. * * Results: * None. * * Side effects: * Stack information is allocated and initialization. * * ---------------------------------------------------------------------------- */ void VmStackInit() { Address addr; int i; Sync_LockInitDynamic(&stackLock, "Vm:stackLock"); stackListElements = (StackList *)Vm_BootAlloc(vmMaxProcesses * sizeof(StackList)); List_Init(activeList); List_Init(freeList); for (i = 0, addr = vmStackBaseAddr; addr < vmStackEndAddr; i++, addr += mach_KernStackSize) { stackListElements[i].startAddr = (Address) addr; List_Insert((List_Links *) &stackListElements[i], LIST_ATREAR(freeList)); } numStackPages = mach_KernStackSize >> vmPageShift; }
int RichUtil_SubClass(HWND hwndEdit) { if (IsWindow(hwndEdit)) { int idx; TRichUtil *ru = (TRichUtil *)mir_calloc(sizeof(TRichUtil)); ru->hwnd = hwndEdit; ru->hasUglyBorder = 0; { mir_cslock lck(csRich); if (!List_GetIndex(&sListInt, ru, &idx)) List_Insert(&sListInt, ru, idx); } mir_subclassWindow(ru->hwnd, RichUtil_Proc); RichUtil_ClearUglyBorder(ru); return 1; } return 0; }