int main(int argc, char const *argv[]) { List L1, L2, L3; Position P; L1 = CreateList(3); PrintList(L1); L2 = CreateList(5); PrintList(L2); L3 = CreateList(2); PrintList(L3); for (P = L1; P -> next != NULL; P = P -> next); P -> next = L3; PrintList(L1); for (P = L2; P -> next != NULL; P = P -> next); P -> next = L3; PrintList(L2); printf("%d\n", getIntersectionNode(L1, L2) -> val); return 0; }
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; }
List *Ast::CreateList(const location& loc, ExprContext ctx, AstNode *seq, AstNode *item) { List *tuple = NULL; if (seq) { tuple = dynamic_cast<List*>(seq); if(!tuple) { tuple = CreateList(loc, ctx); tuple->items.push_back(seq); } } else { tuple = CreateList(loc, ctx); } if(item) { tuple->items.push_back(item); } return tuple; }
int main() { List L1, L2; Stack S1, S2; Position current1, current2; FILE *fpr, *fpi; Position current; int isPalindrome; L1 = CreateEmptyList(); fpr = fopen("linkedlist1.dat", "r"); if(fpr == NULL) { printf("\nFailed to open file!\n"); } CreateList(fpr, L1); L2 = CreateEmptyList(); fpi = fopen("linkedlist2.dat", "r"); if(fpi == NULL) { printf("\nFailed to open file!\n"); exit(0); } CreateList(fpi, L2); PrintList(L1); PrintList(L2); S1 = CreateEmptyStack(); S1 = CreateStackFromList(L1, S1); S2 = CreateEmptyStack(); S2 = CreateStackFromList(L2, S2); PrintStack(S1); PrintStack(S2); isPalindrome = CheckIsPalindrome(L1, S1); if(isPalindrome == 0) { printf("\nThat list is a Palindrome!\n"); } else { printf("\nThat list is not a Palindrome!\n"); } isPalindrome = CheckIsPalindrome(L2, S2); if(isPalindrome == 0) { printf("\nThat list is a Palindrome!\n"); } else { printf("\nThat list is not a Palindrome!\n"); } return 0; }
int main(int argc, char const *argv[]) { List L1, L2, L3; Position P; L1 = CreateList(1); PrintList(L1); printf("%d\n", hasCycle(L1)); for (P = L1; P -> next != NULL; P = P -> next); P -> next = L1; printf("%d\n", hasCycle(L1)); L2 = CreateList(5); PrintList(L2); printf("%d\n", hasCycle(L2)); for (P = L2; P -> next != NULL; P = P -> next); P -> next = L2; printf("%d\n", hasCycle(L2)); L3 = CreateList(2); PrintList(L3); printf("%d\n", hasCycle(L3)); for (P = L3; P -> next != NULL; P = P -> next); P -> next = L3; printf("%d\n", hasCycle(L3)); return 0; }
//------------------------------------------------------------------------------ int main(){ auto list = CreateList( std::vector<int>( {1,2,3,4,5} ) ); std::cout << PrintList( list ) << std::endl; std::cout << PrintBackList( list ) << std::endl; auto listA = CreateList( std::vector<int>( {1,2,3,} ) ); auto listB = CreateList( std::vector<int>( {4,5} ) ); auto ab = Append( listA, listB ); std::cout << PrintList( ab ) << std::endl; auto tree = CreateTree( std::vector<int>( {4,2,1,3,5} ) ); std::cout << PrintTree( tree ) << std::endl; auto treelist = TreeToList( tree ); std::cout << PrintList( treelist ) << std::endl; TestRandomTree(); return EXIT_SUCCESS; }
int main(int argc, const char *argv[]) { Node* head = CreateList(); int v = 5; InsertList(head, v); InsertList(head, v); InsertList(head, v); v = 10; int i = InsertList(head, v, 4); v = 20; i = InsertList(head, v, 4); v = 1; i = InsertList(head, v); printf("i:%d\n", i); PList(head); printf("\n\n"); PListRecurse(head->next); printf("\nreserve list:\n"); ReserveList(head); PList(head); printf("\n---- reserve list\n"); Node* p = GetNode(head, 1); if( NULL != p ) { printf("\n0 node d:%d p:%016lX\n", p->d, reinterpret_cast<uint64_t>(p)); } Node* head2 = CreateList(); head2->next = p; printf("\nlist2\n"); PList(head2); printf("\n"); int retInterSection = CheckUnion(head, head2); printf("checkunion ret:%d\n", retInterSection); int ret = CheckCircle(head); printf("check circle:%d\n", ret); printf("makecircle \n"); MakeCircle(head); //PList(head); retInterSection = CheckUnion(head, head2); printf("checkunion2 ret:%d\n", retInterSection); ret = CheckCircle(head); printf("check circle:%d\n", ret); i = FindInList(head, 20); printf("\nfind i:%d\n", i); return 0; }
int main() { LNode *la,*lb; la=CreateList(la,5); lb=CreateList(lb,6); Output(la); Output(lb); lb=DelInsert(la,lb,2,3,3); Output(lb); return 0; }
int main() { LinkList la,lb,lc,l; la=CreateList(la,7); lb=CreateList(lb,8); lc=CreateList(lc,8); Output(la); Output(lb); la=Merge4(la,lb,lc); Output(la); return 0; }
static void SumTest() { unsigned int number1[] = { 3, 5, 6 }; unsigned int number2[] = { 7, 0, 4, 2, 1 }; IntNode* n1 = CreateList(number1, ARRAY_SIZE(number1)); IntNode* n2 = CreateList(number2, ARRAY_SIZE(number2)); IntNode* sum = Sum(n1, n2); Asserts::IsTrue(sum != 0); unsigned int expectedData[] = { 0, 6, 0, 3, 1 }; std::vector<unsigned int> actual = ToVector(sum); Asserts::AreEqual(expectedData, ARRAY_SIZE(expectedData), actual); }
void CreateList(NodeT* root,NodeL*head) { if (root==NULL) AddLast(head,"*"); else { AddLast(head,root->data); CreateList(root->left,head); CreateList(root->right,head); } }
int main() { ListNode* l1 = NULL; CreateList(l1,3); // 输入数据,长度为3 ListNode* l2 = NULL; CreateList(l2,3); Solution sln; ListNode* results = NULL; results = sln.addTwoNumbers(l1,l2); print(results); while(1); return true; }
LIST *txtGoKeyAndInsert(U32 textId, char *key, ...) { va_list argument; LIST *txtList = CreateList(), *originList = NULL; NODE *node; va_start(argument, key); originList = txtGoKey(textId, key); for (node = LIST_HEAD(originList); NODE_SUCC(node); node = NODE_SUCC(node)) { U8 i; char originLine[256], txtLine[256]; strcpy(originLine, NODE_NAME(node)); strcpy(txtLine, NODE_NAME(node)); for (i = 2; i < strlen(originLine); i++) { if (originLine[i - 2] == '%') { sprintf(txtLine, originLine, va_arg(argument, U32)); i = strlen(originLine) + 1; } } CreateNode(txtList, 0, txtLine); } RemoveList(originList); return txtList; }
bool CArticleList::CreateSubsEditorsAllocationsList(int iSubID, const TDVCHAR* pcUnitType, int iNumberOfUnits) { TDVASSERT(pcUnitType != NULL, "CArticleList::CreateSubsEditorsAllocationsList(...) called with NULL pcUnitType"); CTDVString sUnitType = pcUnitType; sUnitType.MakeLower(); // if we have an SP then use it, else create a new one if (m_pSP == NULL) { m_pSP = m_InputContext.CreateStoredProcedureObject(); } // if SP is still NULL then must fail if (m_pSP == NULL) { TDVASSERT(false, "Could not create SP in CArticleList::CreateSubsEditorsAllocationsList"); return false; } bool bSuccess = true; // now proceed with calling the appropriate stored procedure bSuccess = bSuccess && m_pSP->FetchSubEditorsAllocationsList(iSubID, sUnitType, iNumberOfUnits); // use the generic helper method to create the actual list bSuccess = bSuccess && CreateList(100000, 0); // now set the list type attribute bSuccess = bSuccess && SetAttribute("ARTICLE-LIST", "TYPE", "SUB-ALLOCATIONS"); bSuccess = bSuccess && SetAttribute("ARTICLE-LIST", "UNIT-TYPE", sUnitType); // return success value return bSuccess; }
bool CArticleList::CreateAllocatedRecommendationsList(int iMaxNumber, int iSkip) { TDVASSERT(iMaxNumber > 0, "CArticleList::CreateAllocatedRecommendationsList(...) called with non-positive max number of articles"); // if we have an SP then use it, else create a new one if (m_pSP == NULL) { m_pSP = m_InputContext.CreateStoredProcedureObject(); } // if SP is still NULL then must fail if (m_pSP == NULL) { TDVASSERT(false, "Could not create SP in CArticleList::CreateAllocatedRecommendationsList"); return false; } bool bSuccess = true; // now proceed with calling the appropriate stored procedure bSuccess = bSuccess && m_pSP->FetchAllocatedUnreturnedRecommendations(); // use the generic helper method to create the actual list bSuccess = bSuccess && CreateList(iMaxNumber, iSkip); // now set the list type attribute bSuccess = bSuccess && SetAttribute("ARTICLE-LIST", "TYPE", "ALLOCATED-RECOMMENDATIONS"); // return success value return bSuccess; }
void PlaneListWidget::Prepare(ContainerWindow &parent, const PixelRect &rc) { const DialogLook &look = UIGlobals::GetDialogLook(); CreateList(parent, look, rc, GetRowHeight(look)); UpdateList(); }
/* public functions - TEXT */ void txtInit(char lang) { char txtListPath[DSK_PATH_MAX]; if ((txtBase = TCAllocMem(sizeof(*txtBase), 0))) { txtBase->tc_Texts = CreateList(); txtBase->tc_Language = lang; dskBuildPathName(DISK_CHECK_FILE, TEXT_DIRECTORY, TXT_LIST, txtListPath); if (ReadList(txtBase->tc_Texts, sizeof(struct Text), txtListPath)) { U32 i, nr; nr = GetNrOfNodes(txtBase->tc_Texts); for (i=0; i<nr; i++) { txtLoad(i); } } else { ErrorMsg(No_Mem, ERROR_MODULE_TXT, ERR_TXT_READING_LIST); } } else { ErrorMsg(No_Mem, ERROR_MODULE_TXT, ERR_TXT_FAILED_BASE); } }
END_TEST START_TEST(test_lifo_enqueue_dequeue_multiple) { static const int count = 100; struct PD* entry; int i; struct LL* list = CreateList(L_LIFO); struct PD* pd[count]; // Allocate and add the process descriptors for(i = 0; i < count; i++) { pd[i] = AllocatePD(); pd[i]->pid = i; EnqueueAtHead(pd[i], list); } // Dequeue all process descriptors for(i = 0; i < count; i++) ck_assert(DequeueHead(list) == pd[count - i - 1]); // Cleanup for(i = 0; i < count; i++) DestroyPD(pd[i]); DestroyList(list); }
END_TEST START_TEST(test_lifo_enqueue_multiple) { static const int count = 100; struct PD* entry; int i; struct LL* list = CreateList(L_LIFO); struct PD* pd[count]; // Allocate and add the process descriptors for(i = 0; i < count; i++) { pd[i] = AllocatePD(); pd[i]->pid = i; EnqueueAtHead(pd[i], list); } // Validate the constructed list for(entry = list->head, i = 0; entry; entry = entry->link, i++) ck_assert(pd[count - i - 1] == entry); // Cleanup for(i = 0; i < count; i++) DestroyPD(pd[i]); DestroyList(list); }
void test() { Solution sol; ListNode* head = CreateList({ 1,2,3,4 }); ListNode* ret = sol.rotateRight(head, 0); PrintList(ret); }
void AirspaceListWidget::Prepare(ContainerWindow &parent, const PixelRect &rc) { const DialogLook &look = UIGlobals::GetDialogLook(); CreateList(parent, look, rc, AirspaceListRenderer::GetHeight(look)); UpdateList(); }
int main() { linkedList *list = CreateList(); MainInterface(list); FreeList(list); return 0; }
void Konkat (List L1, List L2, List *L3) { /* Kamus Lokal */ address P, Pt; boolean gagal; /* Algoritma */ CreateList(L3); gagal = false; P = First(L1); while ((P != Nil)&&(!gagal)) { Pt = Alokasi(Info(P)); if (Pt != Nil) { InsertLast(L3,Pt); P = Next(P); } else { gagal = true; DelAll(L3); } } if (!gagal) { P = First(L2); while ((P != Nil)&&(!gagal)) { Pt = Alokasi(Info(P)); if (Pt != Nil) { InsertLast(L3,Pt); P = Next(P); } else { gagal = true; DelAll(L3); } } } }
int main() { char flag; do { List* h; h = (List*)malloc(sizeof(List)); (*h).value = 0; (*h).next = NULL; CreateList(h); int k; printf("请输入k的值:"); scanf("%d", &k); fflush(stdin); int result[2]; Adjmax(h, k, result); printf("序号%d, data值%d\n", result[0], result[1]); FreeList(h); // Finish(); printf("输入N退出,否则继续\n"); scanf("%c", &flag); fflush(stdin); } while(flag != 'N' && flag != 'n'); }
void KeyConfigPrefs::Populate() { ShuttleGui S(this, eIsCreatingFromPrefs); AudacityProject *project = GetActiveProject(); if (!project) { S.StartVerticalLay(true); { S.StartStatic(wxEmptyString, true); { S.AddTitle(_("Keyboard preferences currently unavailable.")); S.AddTitle(_("Open a new project to modify keyboard shortcuts.")); } S.EndStatic(); } S.EndVerticalLay(); return; } mManager = project->GetCommandManager(); mManager->GetCategories(mCats); mCats.Insert(_("All"), 0); PopulateOrExchange(S); CreateList(); mCommandSelected = -1; }
// TODO: Extract inbuilt function handling into separate classes instead of creating massive if/else-monstrosity here // map<std::string(name), FunctionCodeGenerator(inbuild_type)> // can move arithmetic function transformation from semantic analyzer into generator class void CodeGenAstVisitor::Visit(FunctionCallNode *node) { if (node->Name() == FN_IF) { GenerateJumpsForIf(node); } else if (node->Name() == FN_LIST) { CreateList(node); } else if (node->Name() == FN_MAP) { CreateMapping(node); } else if (m_inbuilt_functions.count(node->Name())) { m_function->AddByteCode(ByteCode{ m_inbuilt_functions[node->Name()] }); } else { int id = m_functions[node->Name()].FunctionId(); VMObject o; o.type = VMObjectType::INTEGER; o.value.integer = id; m_function->AddByteCode(ByteCode{ Instruction::PUSH, o }); m_function->AddByteCode(ByteCode{ Instruction::CALLFUNCTION }); } }
int main( void ) { List *list = CreateList( ); node *n; int x = 17; int y = 18; int z = 19; InsertFront( list, &x, sizeof( int ) ); InsertFront( list, &y, sizeof( int ) ); InsertFront( list, &z, sizeof( int ) ); // Loop through list. It's important to use ListBegin and ListEnd for proper looping. // Make note of what pointers Begin and End return. for(n = ListBegin( list ); n != ListEnd( list ); n = n->next) printf( "%d\n", NODE_DATA( n, int ) ); // Proper way to delete nodes from list is like so: // note -- we are not doing n = n->next within the for loop, instead // we use the return value of delete for(n = ListBegin( list ); n != ListEnd( list );) n = DeleteNode( list, n ); getchar( ); return 0; }
LIST *txtGoKey(U32 textId, const char *key) { LIST *txtList = NULL; struct Text *txt = GetNthNode(txtBase->tc_Texts, textId); if (txt) { char *LastMark = NULL; /* MOD: 08-04-94 hg * if no key was given take the next one * -> last position is temporarily saved in LastMark because * txt->LastMark is modified in txtPrepare! * * Special case: no key, text never used !! */ if ((!key) && (txt->txt_LastMark)) LastMark = txt->txt_LastMark; txtPrepare(textId); /* Explanation for +1: LastMark points to the last key -> without "+1" the same key would be returned */ if (!key && LastMark) txt->txt_LastMark = LastMark + 1; for (; *txt->txt_LastMark != TXT_CHAR_EOF; txt->txt_LastMark++) { if (*txt->txt_LastMark == TXT_CHAR_MARK) { U8 found = 1; if (key) { char mark[TXT_KEY_LENGTH]; strcpy(mark, txt->txt_LastMark + 1); if (strcmp(key, mark) != 0) found = 0; } if (found) { U8 i = 1; char *line; txtList = CreateList(); while ((line = txtGetLine(txt, i++))) CreateNode(txtList, 0, line); break; } } } } if (!txtList) { DebugMsg(ERR_ERROR, ERROR_MODULE_TXT, "NOT FOUND KEY '%s'", key); } return txtList; }
void OptionStartsWidget::Prepare(ContainerWindow &parent, const PixelRect &rc) { CreateList(parent, UIGlobals::GetDialogLook(), rc, Layout::GetMaximumControlHeight()); RefreshView(); }
void WaypointManagerWidget::Prepare(ContainerWindow &parent, const PixelRect &rc) { const DialogLook &look = UIGlobals::GetDialogLook(); CreateList(parent, look, rc, row_renderer.CalculateLayout(*look.list.font_bold, look.small_font)); }