[Solved] Sort list numericallyC# [closed]

[ad_1] You can in-place sort scores if you want, using List.Sort(Comparison<T>): scores.Sort((a, b) => int.Parse(a.Punten).CompareTo(int.Parse(b.Punten))); Note that because Punten appears to be a string, you need to convert it to an int to compare properly. If you change your code to make Punten an int, the sorting code would simplify to: scores.Sort((a, b) => a.Punten.CompareTo(b.Punten)); … Read more

[Solved] Please help me correcting this code [closed]

[ad_1] Suggest you to debug it using debugger. Number of issues like ptr1 != ‘0’ should be *ptr1 != ‘\0’ as one stage your loop should fail & it happen by comparing value(*ptr) on that address not by comparing address(ptr). in for loop initialization part ptr1 = &name is wrong it should be ptr1 = … Read more

[Solved] loops and switches in c my code

[ad_1] There are 3 places where i is changed (after the initialization to 1) Check the comments in order A, B, C, … int main() { int i; for(i=1;i<10;i++) // ^^ 6 -> 7 (end of 1st loop) C // ^^ 10 -> 11 (end of 2nd loop) E { switch(i) { case 1: i=i+2; … Read more

[Solved] Let’s talk about struct [closed]

[ad_1] This is an initialization of a static array of struct option elements. This structure will have four elements (char*, other, a pointer, and a character), and these are the values. Note the array is ended with a NULL value to prevent searchs throug it to pass beyond end, and note also how some constants … Read more

[Solved] Get the dot product of two vectors by functors and STL algorithms

[ad_1] Just use std::inner_product: live demo #include <algorithm> #include <iostream> #include <iterator> #include <ostream> #include <numeric> #include <cstdlib> #include <vector> using namespace std; int main() { vector<int> v1,v2; generate_n( back_inserter(v1), 256, rand ); generate_n( back_inserter(v2), v1.size(), rand ); cout << inner_product( v1.begin(), v1.end(), v2.begin(), 0 ) << endl; } Yes, that’s a good solution. But … Read more

[Solved] How to return the frequent/highest repeated word from a List in C#? [duplicate]

[ad_1] This will get the most popular instance of Datum in your abc List var mostPopular = abc .GroupBy(x => x.name) .OrderByDescending(g => g.Count()) .First(); If you want JUST the name value of the most popular append a Select on the end var mostPopularName = abc .GroupBy(x => x.name) .OrderByDescending(g => g.Count()) .First() .Select(x=> x.name); … Read more

[Solved] Getting some part of String c# [closed]

[ad_1] Use Regex. I added a ‘\n’ to and of each line to look like code was read from a file. You can use StreamReader instead of StringReader to read from a file. See code below : using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Text.RegularExpressions; namespace ConsoleApplication51 { class Program { … Read more

[Solved] C function while(*a++ = *b++) with floats

[ad_1] This is not even “valid” code (It would be basically valid, 20 years ago, when variables without type were assumed to be ints). /*int*/ x(/*int*/a,/*int*/ b){ float *a,*b; while(*a++ = *b++); } In the following, I will assume, that a and b are int* (At least in the parameters) This is undefined behavior. float … Read more