[Solved] Heap Sort doesn’t work properly

In the comments, you mention that you’re using array indexes in the interval 1..N for an array of size N+1, but the size you pass in is N+1. If that’s true, you have an off-by-one error in max-heapify(): if size is N+1, the last position you can access is N, not N+1, so you must … Read more

[Solved] sorting in the order of lowercase first then uppercase then digits and sorting the digits to with the odd no first [closed]

I’m assuming this is homework or something and you are supposed to do this a certain way or something? What are the specifications? I shortened your code anyway if that helps in any way p = “Sorting1234” upper_case = sorted([i for i in p if i.isupper()]) lower_case = sorted([i for i in p if i.islower()]) … Read more

[Solved] consider a string which has question marks, numbers , letters [closed]

I leave the refactoring of regex on you, but this is something you can do using String.prototype.match. function checkStr(str) { let match = str.match(/(\d)\?{3}(\d)/); return match && +match[1] + +match[2] === 10; } let out = checkStr(‘bdhfr6???3hfyrt5???eee5’); console.log(out) out = checkStr(‘bdhfr6???4hfyrt5???eee5’); console.log(out) solved consider a string which has question marks, numbers , letters [closed]

[Solved] Algorithms for bucket sort

This is basically a link only answer but it gives you the information you need to formulate a good question. Bucket Sort Wikipedia’s step 1, where you “Set up an array of initially empty buckets”, will need to include buckets for negative numbers. Counting Sort “Compared to counting sort, bucket sort requires linked lists, dynamic … Read more

[Solved] php and mysqli help needed

The problem is that you are getting multiple rows back and storing your id in one variable that gets overwritten every loop. I would recommend you create a class (if u are going the OO way) and add that to the list instead $sortedData = []; class Fotograf { public $Id; public $Firma; } // … Read more

[Solved] PHP usort item missing keys to top [duplicate]

return 1; in your first if there makes no sense – returning 1 means, $a is supposed to be considered greater than $b. So whenever either one of them is missing that value, you always say the first one should be considered the greater one. The return value of the callback function only decides, whether … Read more

[Solved] Sort strings alphabetically AND by length?

tl;dr: the key paths you are looking for are “length” and “self” (or “description” or “uppercaseString” depending on what how you want to compare) As you can see in the documentation for NSSSortDescriptor, a sort descriptor is created “by specifying the key path of the property to be compared”. When sorting string by their length, … Read more

[Solved] Why sort() function causes compilation error when it is used for set of class objects

Two problems. First, you cannot reorder the elements of a set. Their ordering criteria is determined upon construction, it is a fundamental part of the object. This is necessary in order for it to achieve O(log n) lookups, insertions, and deletions, which is part of the promises of std::set. By default, it will use std::less<Edge>, … Read more

[Solved] Sort elements by placing elements with odd number index first and even indexes in the end of an array in C [closed]

you can find a typical solution here ` #include<stdio.h> void swap(int *a, int *b); void segregateEvenOdd(int arr[], int size) { /* Initialize left and right indexes */ int left = 0, right = size-1; while (left < right) { /* Increment left index while we see 0 at left */ while (arr[left]%2 == 0 && … Read more

[Solved] How to sort this list by the highest score?

You can use the sorted function with the key parameter to look at the 2nd item, and reverse set to True to sort in descending order. >>> sorted(data_list, key = lambda i : i[1], reverse = True) [[‘Jimmy’, [8]], [‘Reece’, [8]], [‘Zerg’, [5]], [‘Bob’, [4]]] 2 solved How to sort this list by the highest … Read more

[Solved] Using std::sort to sort an array of C strings

std::sort: The comparison object expected by it has to return ​true if the first argument is less than (i.e. is ordered before) the second. strcmp, the function you provided has another return convention: Negative value if lhs is less than rhs. ​0​ if lhs is equal to rhs. Positive value if lhs is greater than … Read more

[Solved] Min/Max Values of an Array

Methods: public static int getMax(int[] a) and public static int getMin(int[] a) have int[] as their input parameter, but they are later called without any parameters: arr.getMax(); and arr.getMin();. This is the cause of the error you are getting from the compiler. EDIT: You probably want to modify your methods not to be static and … Read more

[Solved] how would i print all the names and scores of those users from a particular class?

Updating answer based on updated question: classdata = {} for data in schooldata: if classdata.get(data[‘class_code’]): classdata[data[‘class_code’]].append(data) else: classdata[data[‘class_code’]] = [data] print classdata To print class data (in orderly manner): for class_data in sorted(classdata): for person_data in sorted(classdata[class_data], key=lambda x: x[‘name’]): print person_data[‘class_code’], person_data[‘name’], person_data[‘score’] 15 solved how would i print all the names and scores … Read more