int main () { Link* norse_gods = new Link("Thor"); norse_gods = norse_gods->insert(new Link("Odin")); norse_gods = norse_gods->insert(new Link("Zeus")); norse_gods = norse_gods->insert(new Link("Freia")); Link* greek_gods = new Link("Hera"); greek_gods = greek_gods->insert(new Link("Athena")); greek_gods = greek_gods->insert(new Link("Mars")); greek_gods = greek_gods->insert(new Link("Poseidon")); Link* g = greek_gods->find("Mars"); if (g) g->value = "Ares"; Link* n = norse_gods->find("Zeus"); if (n == norse_gods) norse_gods = n->next(); n->erase(); greek_gods = greek_gods->insert(n); print_all(norse_gods); cout << "======================" << endl; print_all(greek_gods); keep_window_open(); }
int main() { Link* gods = new Link{God{"Athena", "Greek", "", "knowledge"}}; gods = gods->insert(new Link{God{"Loki", "Norse", "", "Loki's staff"}}); gods = gods->insert(new Link{God{"Poseidon", "Greek", "", "water"}}); gods = gods->insert(new Link{God{"The Many-Faced", "ASoIaF", "masks", "death"}}); gods = gods->insert(new Link{God{"Zeus", "Greek", "", "lightning"}}); gods = gods->insert(new Link{God{"R'hllor", "ASoIaF", "prayer", "fire"}}); gods = gods->insert(new Link{God{"Thor", "Norse", "Rainbow Bridge", "Mjolnir"}}); gods = gods->insert(new Link{God{"The Other", "ASoIaF", "dead things", "ice"}}); gods = gods->insert(new Link{God{"Odin", "Norse", "Sleipner", "Gungir"}}); Link* greek_gods; Link* norse_gods; Link* iceandfire_gods; while (gods) { if (gods->value.mythology == "Greek") { greek_gods = greek_gods->insert(new Link{gods->value}); } else if (gods->value.mythology == "Norse") { norse_gods = norse_gods->insert(new Link{gods->value}); } else if (gods->value.mythology == "ASoIaF") { iceandfire_gods = iceandfire_gods->insert(new Link{gods->value}); } gods = gods->next(); } print_all(iceandfire_gods); print_all(norse_gods); print_all(greek_gods); }
int main() { Link* norse_gods = new Link {"Thor"}; norse_gods = norse_gods->insert( new Link {"Odin"}); norse_gods = norse_gods->insert(new Link {"Zeus"}); norse_gods = norse_gods->insert(new Link {"Loki",}); Link* greek_gods = new Link {"Hera"}; greek_gods = greek_gods->insert(new Link {"Athena"}); greek_gods = greek_gods->insert(new Link {"Mars"}); greek_gods = greek_gods->insert(new Link {"Poseidon"}); Link* p = greek_gods->find("Mars"); //std::cout << norse_gods->succ->value << " : " << greek_gods->succ->value << std::endl; if (p) p->value = "Ares"; //std::cout << norse_gods->succ->value << " : " << greek_gods->succ->value << std::endl; Link* p2 = norse_gods->find("Zeus"); if (p2) { if (p2 == norse_gods) norse_gods = norse_gods->next(); p2->erase(); greek_gods = greek_gods->insert(p2); } //std::cout << norse_gods->value << " : " << greek_gods->succ->value << std::endl; print_all(norse_gods); greek_gods = greek_gods->add(new Link {"Hades"}); greek_gods = greek_gods->previous(); print_all(greek_gods); /*Chapter 17 Exercise 12 Why did we define two versions of find()? */ const Link* const_test = new const Link {"Test"}; const Link* sp = const_test->find("Test"); std::cout << sp->value << std::endl; std::cout << greek_gods->previous() << std::endl; }
int main() { print_all(1, 3.14, 'c', "Hello"); std::cout << std::endl; print_all(1, 'c'); }
void print_all(TREE_NODE *root, print_function f, int level){ if (root) { f(root, level); print_all(root->left, f, level + 1); print_all(root->right, f, level + 1); } }
int main(void){ int a[] = {2, 8, 5, 1, 9, 4}; print_all(a, ARRAY_LEN(a)); printf("\n"); insertion_sort(a, ARRAY_LEN(a)); printf("\n"); print_all(a, ARRAY_LEN(a)); return 0; }
int main() { // norse gods God god_temp = God{"Thor", "A chariot pulled by two goats (that he eats and" " resurrects", "Mountain-crushing hammer called Mjolnir", Mythology::Norse}; Link* norse_gods{new Link{god_temp, nullptr, nullptr}}; god_temp = God{"Odin", "Eight-legged flying horse called Sleipnir", "Spear called Gungnir", Mythology::Norse}; norse_gods = norse_gods->add_ordered(new Link{god_temp}); god_temp = God{"Freia", "A chariot pulled by two cats", "A feathered cloak", Mythology::Norse}; norse_gods = norse_gods->add_ordered(new Link{god_temp}); // greek gods god_temp = God{"Zeus", "The Chariot of Zeus", "Thunderbolts", Mythology::Greek}; Link* greek_gods{new Link{god_temp, nullptr, nullptr}}; god_temp = God{"Athena", "None", "An extremely long spear", Mythology::Greek}; greek_gods = greek_gods->add_ordered(new Link{god_temp}); god_temp = God{"Ares", "His war chariot", "A spear and helmet", Mythology::Greek}; greek_gods = greek_gods->add_ordered(new Link{god_temp}); god_temp = God{"Poseidon", "A chariot pulled by a winged hippocampus, or" " horses that can ride on the sea itself", "A trident", Mythology::Greek}; greek_gods = greek_gods->add_ordered(new Link{god_temp}); // Egyptian gods god_temp = God{"Osiris", "None", "A crook and flail", Mythology::Egyptian}; Link* egypt_gods{new Link{god_temp, nullptr, nullptr}}; god_temp = God{"Ra", "The sun", "The power of creation", Mythology::Egyptian}; egypt_gods = egypt_gods->add_ordered(new Link{god_temp}); god_temp = God{"Shu", "The wind", "Power to hold up the sky", Mythology::Egyptian}; egypt_gods = egypt_gods->add_ordered(new Link{god_temp}); print_all(norse_gods); std::cout << '\n'; print_all(greek_gods); std::cout << '\n'; print_all(egypt_gods); std::cout << '\n'; return 0; }
void main(void) { printf("[+] Creating a Linked-list 1~5.\n"); NodePtr testData = create_list(1,5); print_all(testData); puts("Let me swap it adjacently! swap(3,4)"); swap(testData,testData->next->next,testData->next->next->next); print_all(testData); puts("Let me change between head and tail. swap(1,5)"); NodePtr tail=testData; while(tail->next) tail = tail->next; print_all(swap(testData,testData,tail)); }
void print_last_n(LIST* head, int n, FILE* g) { int na = list_length(head); if (n >= na) { print_all(head, g); } else { LIST* t = head; for (int i = 0; i < na - n; i++) { t = t->next; } print_all(t, g); } }
void print_all(struct node obj){ if(&obj!=NULL){ if(obj.name=='S'||obj.name=='I'||obj.name=='D'||obj.name=='C'){ if(obj.prev!=NULL) print_all(*obj.prev); if(obj.value!=NULL) { print_node(obj); } if(obj.next!=NULL) print_all(*obj.next); } } }
int main() { Link* norse_gods = new Link("Thor"); norse_gods = norse_gods->insert(new Link("Odin")); norse_gods = norse_gods->insert(new Link("Zeus")); norse_gods = norse_gods->insert(new Link("Freia")); Link* greek_gods = new Link("Hera"); greek_gods = greek_gods->insert(new Link("Athena")); greek_gods = greek_gods->insert(new Link("Mars")); greek_gods = greek_gods->insert(new Link("Poseidon")); Link* p = greek_gods->find("Mars"); if (p) p->value = "Ares"; // Move Zeus into his correct Pantheon: { Link* p = norse_gods->find("Zeus"); if (p) { if (p==norse_gods) norse_gods = p->next(); p->erase(); greek_gods = greek_gods->insert(p); } } norse_gods->add(new Link("loki")); // Finally, let's print out those lists: print_all(norse_gods); cout<<"\n"; norse_gods=norse_gods->advance(2); // test advance print_all(norse_gods); cout<<"\n"; print_all(greek_gods); cout<<"\n"; cout<<greek_gods->node_count()<<endl; // test node count Link* god_list=new Link("Apollo"); god_list=god_list->add(new Link("Aphrodite")); god_list=god_list->add(new Link("Artemis")); god_list=god_list->add(new Link("Hades")); god_list=god_list->first(); print_all(god_list); cout<<endl; keep_window_open(); }
void editfile (list_ref list, char *filename) { char stdinline[1024]; int stdincount = 0; for(;; ++stdincount) { printf ("%s: ", Exec_Name); char *linepos = fgets (stdinline, sizeof stdinline, stdin); if (linepos == NULL) break; if (want_echo) printf ("%s", stdinline); linepos = strchr (stdinline, '\n'); if (linepos == NULL || stdinline[0] == '\0') { badline (stdincount, stdinline); }else { *linepos = '\0'; switch (stdinline[0]) { case '$': setmove_list(list, MOVE_LAST, stdinline); break; case '*': print_all(list, stdinline); break; case '.': viewcurr_list(list, stdinline); break; case '0': setmove_list(list, MOVE_HEAD, stdinline); break; case '<': setmove_list(list, MOVE_PREV, stdinline); break; case '>': setmove_list(list, MOVE_NEXT, stdinline); break; case '@': debugdump_list (list, stdinline); break; case 'a': insert_line_after (list, stdinline+1); break; case 'd': delete_list(list, stdinline); break; case 'i': insert_line_before(list, stdinline+1); break; case 'r': insertfile(list, stdinline+1); break; case 'w': writefile (list, stdinline+1, filename); break; default : badline (stdincount, stdinline); } } } printf("%s\n", "^D"); }
/** * check_count_free_list -Check for count of free blocks, iterating over blocks * and by going through next pointers */ static void check_count_free_list() { void *bp; unsigned int counti = 0; unsigned int countp = 0; /*Iterate over list*/ for (bp = heap_listp; GET_SIZE(HDRP(bp)) > 0; bp = NEXT_BLKP(bp)) { if(!GET_ALLOC(HDRP(bp))) { counti++; } } /* Moving free list by pointers*/ for (int i = 0; i < NO_OF_LISTS; i++) { for (bp = GET_SEGI(seg_list,i); (bp!=NULL) && (GET_SIZE(HDRP(bp)) > 0);bp = GET_NEXTP(bp)) { countp++; } } /*If count is not matching, print error, with debug Info*/ if(countp!=counti) { printf("ERROR: No. of free block mismatch\n"); dbg_printf("free\n"); print_free(); dbg_printf("all\n"); print_all(); } }
void commandlist(int command){ switch(command){ case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: print_run(command); break; case 10: recover_run(); break; case 11: print_all(); break; case 12: win_stats(); break; case 13: best_class(); break; case 14: worst_class(); break; case 15: played_class(); break; case 16: myelo(); break; case 21: case 22: case 23: case 24: case 25: case 26: case 27: case 28: case 29: class_win_stats(command); break; } }
int main(void) { int arr[2][4]={1,2,3,4,5,6,7,8}; int i; i=sizeof(arr)/sizeof(*arr); print_all(arr,i); return 0; }
int main() { cout << "Hello, World!\n" ; print_all(cout, "Hello", " World", '!', 0 ,'\n'); ui_history h(1); current(h).emplace_back("Hello"); current(h).emplace_back("World"); current(h).emplace_back("1"); current(h).emplace_back("2"); current(h).emplace_back("3"); current(h).emplace_back("4"); current(h).emplace_back("5"); current(h).emplace_back("6"); current(h).emplace_back("7"); current(h).emplace_back("8"); current(h).emplace_back("9"); current(h).emplace_back("10"); current(h).emplace_back(my_class_t()); current(h).operator[](1).test(); current(h)[1].test(); ui_object uio = current(h)[1]; uio.test(); auto &uior = current(h)[1]; uior.test(); ?? boost::uuids::uuid ot = uior.get_tag();
int main() { struct toys mine; init(&mine); print_all(mine); return 0; }
void queue::menu() { FILE* ff; char d[60]; int m = 0; setlocale(LC_ALL, "Russian"); do { system("CLS"); if (!fopen_s(&ff, "menu_queue.dpd", "r") == NULL) { printf_s("Error 2"); } fseek(ff, 0, SEEK_SET); while (fgets(d, 59, ff) != NULL) { printf_s("%s", d); } fclose(ff); scanf_s("%d", &m); switch (m) { case(1) : add_many(); break; case(2) : take(); _getch(); break; case(3) : print_all(); break; default: break; } } while (m); }
int main() { struct hotel plaza; int ans,i; init_hotel(&plaza); // Asks the user to check out rooms. printf("Would you like check in(1), or check out(2) or quit(4)?"); scanf("%d", &ans); // Execute the user's choices until they quit. while (ans != 4) { if (ans == 1) get_room(&plaza); else if (ans == 2) check_out(&plaza); else if (ans == 3) print_all(&plaza); // Get the user's next choice. printf("Would you like check in(1), or check out(2) or quit(3)?"); scanf("%d", &ans); } return 0; }
int main(int argc, const char *argv[]) { i = 0; int n = 0; while ( scanf("%d%c", &op[i].integer , &op[i].operator ) != EOF ) { while ( op[i].operator == ' ') { scanf("%c", &op[i].operator); } i++; if ( op[i - 1].operator == '=' ) { scanf("%s",&var_name); if ( n == 0 ) { n++; } else { printf("\n"); } print_all(); while ( i > 1 ) { cal(); } i = 0; } } return 0; }
void cal() { int j,p = 0; for ( j = 0 ; j < i ; j++ ) { if ( op[j].operator == '*' || op[j].operator == '/' ) { p = j; break; } } switch ( op[p].operator ) { case '+': op[p].integer = op[p].integer + op[p + 1].integer; break; case '-': op[p].integer = op[p].integer - op[p + 1].integer; break; case '*': op[p].integer = op[p].integer * op[p + 1].integer; break; case '/': op[p].integer = op[p].integer / op[p + 1].integer; break; } op[p].operator = op[p + 1].operator; for ( j = p + 1 ; j < i - 1 ; j++ ) { op[j] = op[j + 1]; } i--; print_all(); }
int main() { struct clinkedlist* last; last = NULL; int choice; int value; int p, s, l, d; while(1) { printf("Choices:\n"); printf("1. Insert at beginning\n"); printf("2. Print all the nodes\n"); printf("3. Print Smallest\n"); printf("4. Print largest\n"); printf("5. Print largest - smallest\n"); printf("6. Exit\n"); printf("Enter your choice:\n"); scanf("%d", &choice); switch(choice) { case 1: printf("Enter value to be inserted:\n"); scanf("%d", &value); last = insert_beg(last,value); break ; case 2: print_all(last); break ; case 3: s = smallest(last); if (s != 0) { printf("%d\n", s); break; } printf("List is Empty!!\n"); break; case 4: l = largest(last); if (l != 0) { printf("%d\n", l); break; } printf("List is Empty!!\n"); break; case 5: d = difference(last); if (d != 0) { printf("%d\n", d); break; } printf("List is Empty!!\n"); break; case 6: exit(1); default: printf("Invalid Choice!\n"); } } return 0; }
//Called when module unloaded using 'rmmod' void cleanup_module() { print_all(); nf_unregister_hook(&nfho); //cleanup – unregister hook //TODO - cleanup hash table kfree(ts); int i; for(i = 0; i < GLOBAL_MAP_SIZE; i++){ if(global_map[i]){ struct hlist_node* n; struct hlist_node* old; hte_t* h; /* hlist_for_each(n, global_map[i]){ h = hlist_entry(h, hte_t, node); hlist_del(n); //if(h) kfree(h); //kfree(n); } */ n = global_map[i]->first; while(n){ h = hlist_entry(n,hte_t, node); old = n; n = n->next; hlist_del(old); //kfree(old); kfree(h); } kfree(global_map[i]); } } kfree(global_map); }
int main() { std::vector<int> v; v.push_back(42); v.push_back(1337); v.push_back(1729); std::map<int, std::string> m; m[0] = "Hello"; m[1] = "World"; m[2] = "!!"; print_all(v, std::cout); print_all(m, std::cout); }
void thread_cache::rise(string const &trigger) { rwlock_wrlock lock(access_lock); if(debug_mode) print_all(); pair<triggers_ptr,triggers_ptr> range=triggers.equal_range(trigger); triggers_ptr p; list<pointer> kill_list; for(p=range.first;p!=range.second;p++) { kill_list.push_back(p->second); } list<pointer>::iterator lptr; if(debug_mode){ string out=str(boost::format("Trigger [%1%] dropping: ") % trigger); write(fd,out.c_str(),out.size()); } for(lptr=kill_list.begin();lptr!=kill_list.end();lptr++) { if(debug_mode) { write(fd,(*lptr)->first.c_str(),(*lptr)->first.size()); write(fd," ",1); } delete_node(*lptr); } if(debug_mode) write(fd,"\n",1); }
static void test1(void) { literal_t l0, l1, l2; printf("*************************\n"); printf("* TEST 1 *\n"); printf("*************************\n"); init_gate_table(&table); printf("\n--- Initial table ---\n"); print_all(stdout); l0 = pos_lit(4); l1 = pos_lit(5); l2 = pos_lit(6); test_orgate(l0, l1, l2); test_orgate(l0, l1, l2); printf("\n--- After addition ---\n"); print_all(stdout); gate_table_push(&table); gate_table_push(&table); printf("\n--- Push: level 2 ---\n"); print_all(stdout); l0 = pos_lit(4); l1 = pos_lit(5); l2 = pos_lit(6); test_orgate(l0, l1, l2); l0 = pos_lit(5); l1 = pos_lit(6); l2 = pos_lit(7); test_orgate(l0, l1, l2); test_orgate(l0, l1, l2); printf("\n--- After addition ---\n"); print_all(stdout); gate_table_push(&table); printf("\n--- Push: level 3 ---\n"); print_all(stdout); gate_table_pop(&table); printf("\n--- Pop: level 2 ---\n"); print_all(stdout); gate_table_pop(&table); printf("\n--- Pop: level 1 ---\n"); print_all(stdout); gate_table_pop(&table); printf("\n--- Pop: level 0 ---\n"); print_all(stdout); delete_gate_table(&table); }
void thread_cache::store(string const &key,set<string> const &triggers_in,time_t timeout_in,archive const &a) { rwlock_wrlock lock(access_lock); if(debug_mode) print_all(); pointer main; if(debug_mode) { string res; res=str(boost::format("Storing key [%1%], triggers:") % key); for(set<string>::iterator ps=triggers_in.begin(),pe=triggers_in.end();ps!=pe;ps++) { res+=*ps; res+=" "; } res+="\n"; write(fd,res.c_str(),res.size()); } main=primary.find(key); if(main==primary.end() && primary.size()>=limit && limit>0) { if(debug_mode) { char const *msg="Not found, size limit\n"; write(fd,msg,strlen(msg)); } time_t now; time(&now); if(timeout.begin()->first<now) { main=timeout.begin()->second; if(debug_mode) { string res; res=str(boost::format("Deleting timeout node [%1%] with " "delta of %2% seconds\n") % main->first % (now - main->second.timeout->first)); write(fd,res.c_str(),res.size()); } } else { main=lru.back(); if(debug_mode) { string res; res=str(boost::format("Deleting LRU [%1%]\n") % main->first); write(fd,res.c_str(),res.size()); } } } if(main!=primary.end()) delete_node(main); pair<pointer,bool> res=primary.insert(pair<string,container>(key,container())); main=res.first; container &cont=main->second; cont.data=a.get(); lru.push_front(main); cont.lru=lru.begin(); cont.timeout=timeout.insert(pair<time_t,pointer>(timeout_in,main)); if(triggers_in.find(key)==triggers_in.end()){ cont.triggers.push_back(triggers.insert(pair<string,pointer>(key,main))); } set<string>::const_iterator si; for(si=triggers_in.begin();si!=triggers_in.end();si++) { cont.triggers.push_back(triggers.insert(pair<string,pointer>(*si,main))); } }
int main(int argc, char **argv) { FILE* fh; fh = fopen("ratings.dat", "rb"); fread(r, sizeof(RATING), NUM_SLOTS, fh); fclose(fh); print_all(); }
void print_all(LINE_PTR head) { if(head->next) { print_all(head->next); } printf("vale : %d 地址 %p\n",head->vale,head); }
void print_all(int cur, int i) { path[cur] = i; if(d[i] == 1) { for(int j = 0; j <= cur; j++) printf("%d ", path[j]); printf("\n"); } for(int j = 1; j <= n; j++) if(G[i][j] && d[i] == d[j]+1) print_all(cur+1, j); }