void main() { struct Node item0, item1, item2, item3; item0.value = 90; item0.next = &item1; item1.value = 100; item1.next = &item2; item2.value = 110; item2.next = &item3; item3.value = 120; item3.next = NULL; printf("The initial list is....\n"); DisplayList(&item0); printf("After deleting the 3rd item, the list is...\n"); DeleteNode(&item0, &item2); DisplayList(&item0); printf("After adding the previously deleted 3rd item at the last location..\n"); InsertNode(&item3, &item2); DisplayList(&item0); }
int main() { HEAD head; InitDHead(&head); for (int i = 1; i<=8; i++) { InsertDHead(&head, i * 10); //InsertDTail(&head, i * 10); } printf("\n"); //InsertDByPos(&head, 6, 5); //DeleteWhat(&head, 10); //DeleteWhere(&head, 10); //DisplayList(&head); //fanDList(&head); printf("%d\n", GetlengDList(&head)); //InsertDByPos(&head, 10, 5); DisplayList(&head); int k = GetlengDList(&head); for (int i = 0; i < k; i++) { printf("0x%p ", head.arr[i]); } printf("\n"); //huan_Dlist(&head); DestoryDList(&head); //free(head.arr); return 0; }
void GLWidget::initializeGL() { qglClearColor(Qt::gray); glClearDepth(1.0); glShadeModel(GL_FLAT); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST); t = startTimer(50); DisplayList(); }
void CBookManageDlg::OnBnClickedReflash() { // TODO: 在此添加控件通知处理程序代码 m_list.SetRedraw(FALSE); m_list.DeleteAllItems(); RunTimer timer; map.RemoveAll();//也更新哈希表 DisplayList(tree->GetRoot()); EndTime(timer); m_list.SetRedraw(TRUE); }
int main(){ int i; node *root = (node*) malloc( sizeof(node) ); root->value = 2; root->next = NULL; DisplayList(root); for(i = 3; i < 8; i++) InsertTail(&root, i); for(i = 1; i >= 0; i--) InsertHead(&root, i); DisplayList(root); ClearList(&root); DisplayList(root); return 0; }
void Service::SortByYear() { int j; for (unsigned int i = 0; i < Persons.size(); i++){ j = i; while (j > 0 && Persons[j].Byear < Persons[j-1].Byear) { swap(Persons[j],Persons[j-1]); j--; } } DisplayList(); }
int main(int argc, char const *argv[]) { /* code */ List * newList = emptyList(); Insert(2, -1, newList); Insert(3, -1, newList); Insert(20, -1, newList); Insert(40, -1, newList); Insert(8, -1, newList); Insert(23, -1, newList); Insert(91, -1, newList); Insert(4, -1, newList); Insert(10, -1, newList); DisplayList(newList); Insert(75, 3, newList); DisplayList(newList); Remove(5, newList); DisplayList(newList); return 0; }
int main() { int i; INT_LIST *head = NULL, *tail = NULL; int a[] = {1,2,3,4,5,6,7,8,9,10}; for (i = 0; i < ARRAY_SIZE(a); ++i) AddToList(&a[i], &head, &tail); DisplayList(head); for (i = 1; i <= ARRAY_SIZE(a); ++i) printf ("%dth element from last = %d\n", i, FindNthElementFromLast(head, i)); printf ("%dth element from last = %d\n", 11, FindNthElementFromLast(head, 11)); printf ("%dth element from last = %d\n", 0, FindNthElementFromLast(head, 0)); return 0; }
CmdResult HandleLocal(const std::vector<std::string>& parameters, LocalUser* src) { Channel* const chan = ServerInstance->FindChan(parameters[0]); if (!chan) { src->WriteNumeric(Numerics::NoSuchNick(parameters[0])); return CMD_FAILURE; } if (parameters.size() == 1) { DisplayList(src, chan); return CMD_SUCCESS; } unsigned int i = 1; Modes::ChangeList modes; while (i < parameters.size()) { std::string prop = parameters[i++]; if (prop.empty()) continue; bool plus = prop[0] != '-'; if (prop[0] == '+' || prop[0] == '-') prop.erase(prop.begin()); ModeHandler* mh = ServerInstance->Modes->FindMode(prop, MODETYPE_CHANNEL); if (mh) { if (mh->NeedsParam(plus)) { if (i != parameters.size()) modes.push(mh, plus, parameters[i++]); } else modes.push(mh, plus); } } ServerInstance->Modes->ProcessSingle(src, chan, NULL, modes, ModeParser::MODE_CHECKACCESS); return CMD_SUCCESS; }
CmdResult Handle(const std::vector<std::string> ¶meters, User *src) { if (parameters.size() == 1) { Channel* chan = ServerInstance->FindChan(parameters[0]); if (chan) DisplayList(src, chan); return CMD_SUCCESS; } unsigned int i = 1; std::vector<std::string> modes; modes.push_back(parameters[0]); modes.push_back(""); while (i < parameters.size()) { std::string prop = parameters[i++]; bool plus = prop[0] != '-'; if (prop[0] == '+' || prop[0] == '-') prop.erase(prop.begin()); for(char letter = 'A'; letter <= 'z'; letter++) { ModeHandler* mh = ServerInstance->Modes->FindMode(letter, MODETYPE_CHANNEL); if (mh && mh->name == prop) { modes[1].append((plus ? "+" : "-") + std::string(1, letter)); if (mh->GetNumParams(plus)) { if (i != parameters.size()) modes.push_back(parameters[i++]); } } } } ServerInstance->Modes->Process(modes, src); return CMD_SUCCESS; }
void CBookManageDlg::DisplayList(pBTNode T) { int i,row; CString s; DataType data; pBookList p,q; if(T!=NULL) { for(i=1;i<=T->keynum;i++) { data=T->key[i]; row=m_list.GetItemCount(); s.Format(_T("%d"),data.no); m_list.InsertItem(row,s); m_list.SetItemText(row,1,data.name); m_list.SetItemText(row,2,data.author); s.Format(_T("%d"),data.current_num); m_list.SetItemText(row,3,s); s.Format(_T("%d"),data.total_num); m_list.SetItemText(row,4,s); q=new BookList; q->no=data.no; if(map.Lookup(data.author,p)==TRUE) { q->next=p; } else { q->next=NULL; } map[data.author]=q; } for(i=0;i<=T->keynum;i++)DisplayList(T->ptr[i]); } }
void Service::SortByName() { sort(Persons.begin(), Persons.end()); DisplayList(); }
void TestMergeSort(int arraySize) { printf("Testing MergeSort...\n"); int low = 0; int high = arraySize; int A[arraySize]; int B[arraySize]; double duration; clock_t t; // ACEDNING DATA for(int i = 0; i<arraySize; i++ ) A[i] = i; //filled array 0,1,2,...,8,9 #ifndef DEBUG printf("\nData BEFORE Sort: "); DisplayList(A, arraySize); #endif t = clock(); MergeSort(A, high); //sort call #ifndef DEBUG printf("\nData AFTER Sort: "); DisplayList(A, arraySize); #endif t = clock() - t; duration = ExecutionTime( t, CLOCKS_PER_SEC ); printf("\n\t INC ORDER TIME: \t%f sec\n", duration); // RAN DATA for(int i = 0; i<arraySize; i++ ) A[i] = rand()%MAX_SIZE; //RAN values 0-9 t = clock(); #ifndef DEBUG printf("\nData BEFORE Sort: "); DisplayList(A, arraySize); #endif MergeSort(A, high); //sort call #ifndef DEBUG printf("\nData AFTER Sort: "); DisplayList(A, arraySize); #endif t = clock() - t; duration = ExecutionTime( t, CLOCKS_PER_SEC ); printf("\n\t RAN DATA TIME: \t%f sec\n", duration); // DEC DATA for(int i = arraySize; i>0; i-- ) A[arraySize-i] = i; //filled array 10,9,8,...,2,1 t = clock(); #ifndef DEBUG printf("\nData BEFORE Sort: "); DisplayList(A, arraySize); #endif MergeSort(A, high); //sort call #ifndef DEBUG printf("\nData AFTER Sort: "); DisplayList(A, arraySize); #endif t = clock() - t; duration = ExecutionTime( t, CLOCKS_PER_SEC ); printf("\n\t DEC DATA TIME: \t%f sec\n", duration); }
//------------------------------------------------------------------------------ // Main Program //------------------------------------------------------------------------------ int main() { // Table dimensions variables int iRow, iColumn; // Get dimensions while(1) { system("cls"); // Clear Screen printf("Give array dimensions.\nRows:"); scanf("%d", &iRow); printf("Columns:"); scanf("%d", &iColumn); if ((iRow > 1 && iRow <= MAX_ROW) && (iColumn > 1 && iColumn <= MAX_COLUMN)) break; } // Create the array int** iArray = Allocate_2D_Array(iRow, iColumn); // Create list's head pointer struct node* pHead = NULL; // Create list's tail pointer struct node* pTail = NULL; // Create the first node which contains the array's dimensions // pHead now points to that node if (! AddNode(&pHead, iRow, iColumn, 0)) exit(1); // Get array values int i, j; for (i = 0; i < iRow; i++) { for (j = 0; j < iColumn; j++) { printf("Give the [%d][%d] element:", i, j); scanf("%d", &iArray[i][j]); // If not a zero value then add node if (iArray[i][j] != 0) { // Locate the tail node and store its address in pTail LocateTail(pHead, &pTail); // Add new node after the last node (tail node) if (! AddNode(&pTail->m_pNext, i, j, iArray[i][j])) exit(1); } } printf("\n"); } // Show msg printf("Single Linked List created successfully\n\n"); int quit = FALSE; while (quit == FALSE) { printf("Press any key to continue..."); getch(); switch(MenuSelection()) { case 1: { DisplayArray(iArray, iRow, iColumn); break; } case 2: { DisplayList(pHead); break; } case 3: { int** iArrayTwo = Allocate_2D_Array(pHead->m_iX_Pos, pHead->m_iY_Pos); for (i = 0; i < pHead->m_iX_Pos; i++) for (j = 0; j < pHead->m_iY_Pos; j++) iArrayTwo[i][j] = 0; struct node* pCurrent = pHead; while (pCurrent != NULL) { if (pCurrent->m_iData != 0) iArrayTwo[pCurrent->m_iX_Pos][pCurrent->m_iY_Pos] = pCurrent->m_iData; pCurrent = pCurrent->m_pNext; } printf("New Array created successfully: \n\n"); DisplayArray(iArrayTwo, pHead->m_iX_Pos, pHead->m_iY_Pos); printf("\nThe program will now exit\n\n"); DeleteDynArray(iArrayTwo, pHead->m_iX_Pos); quit = TRUE; break; } case 4: { quit = TRUE; break; } } } // Free dynamic allocated memory - 2D Arrays + List DeleteDynArray(iArray, iRow); DeleteList(pHead); system("pause"); return 0; }
void NBT::DisplayTag(NBT_Tag * src, string childStr) { // display tag to screen TagType t = src->getType(); // use own handler, ignore it if(t == TAGTYPE_COMPOUND) { // Recursively parse compound tag DisplayCompound((TAG_Compound*)src, childStr); return; } cout << childStr; string tagName = ""; if(src->getNameHolder().length > 0) { tagName = "(\""; tagName += src->getName(); tagName += "\")"; } switch(t) { case TAGTYPE_BYTE: cout << "TAG_Byte" << tagName.c_str() << ": "; cout << (unsigned short)(0 << 8 | ((TAG_Byte*)src)->getPayload()); cout << endl; break; case TAGTYPE_BYTE_ARRAY: cout << "TAG_Byte_Array" << tagName.c_str() << ": ["; cout << ((TAG_Byte_Array*)src)->size(); cout << " bytes]" << endl; break; case TAGTYPE_DOUBLE: cout << "TAG_Double" << tagName.c_str() << ": "; cout << ((TAG_Double*)src)->getPayload(); cout << endl; break; case TAGTYPE_FLOAT: cout << "TAG_Float" << tagName.c_str() << ": "; cout << ((TAG_Float*)src)->getPayload(); cout << endl; break; case TAGTYPE_INT: cout << "TAG_Int" << tagName.c_str() << ": "; cout << ((TAG_Int*)src)->getPayload(); cout << endl; break; case TAGTYPE_LONG: cout << "TAG_Long" << tagName.c_str() << ": "; cout << ((TAG_Long*)src)->getPayload(); cout << endl; break; case TAGTYPE_SHORT: cout << "TAG_Short" << tagName.c_str() << ": "; cout << ((TAG_Short*)src)->getPayload(); cout << endl; break; case TAGTYPE_STRING: cout << "TAG_String" << tagName.c_str() << ": "; cout << ((TAG_String*)src)->getPayload().value; cout << endl; break; case TAGTYPE_LIST: cout << "TAG_List" << tagName.c_str() << ": "; DisplayList((TAG_List*)src, childStr); cout << endl; break; } }
int main() { List myList; int exit, val, pos; char command; myList = CreateList(); exit = FALSE; while (!exit) { fflush(stdin); printf("\nEnter command \n\ni)nitialize \nn)ew element \nd)elete element \nf)ind element \np)osition of element \nh)ead of list \nt)ail of list \ns)orted insert \ne)xit\n\nCOMMAND: "); scanf("%c", &command); fflush(stdin); switch(command) { case 'i': MakeEmptyList(myList); break; case 'n': printf("enter value: "); scanf("%d", &val); printf("enter position: "); scanf("%d", &pos); InsertList(myList, pos, val); break; case 'd': printf("enter value: "); scanf("%d", &val); DeleteList(myList, val); break; case 'p': printf("enter value: "); scanf("%d", &val); pos = GetPositionOfElement(myList, val); if (pos > 0) printf("element %d at position %d\n", val, pos); break; case 'f': printf("enter position: "); scanf("%d", &pos); val = GetElementAtPosition(myList, pos); if (val >= 0) printf("element at position %d is %d\n", pos, val); break; case 'h': val = HeadOfList(myList); if (val != -1) printf("front element is %d\n", val); break; case 't': val = TailOfList(myList); if (val != -1) printf("rear element is %d\n", val); break; case 'e': exit = TRUE; break; case 's': printf("enter value: "); scanf("%d", &val); sortedInsert (myList, val); break; default: printf("command not recognized\n"); break; } DisplayList(myList); } printf("\n\n"); system("PAUSE"); return 0; }