[Solved] Algorithm for all subsets of Array

You can build a backtracking based solution to formulate all the possible sub-sequence for the given array. Sharing an ideone link for the same: https://ideone.com/V0gCDX all = [] def gen(A, idx = 0, cur = []): if idx >= len(A): if len(cur): all.append(cur) return gen(A, idx + 1, list(cur)) incl = list(cur) incl.append(A[idx]) gen(A, idx … Read more

[Solved] How to sort numeric value in file

To read a file of “lines” in Java you can use the Files class like this: final List<String> l = Files.readAllLines(Paths.get(“/some/path/input.txt”)); This reads a file and stores each line in a List. When you have the List of String objects you can use a simple Comparator and the Collections.sortmethod. Check this code out: final List<String> … Read more

[Solved] How to check if a IEnumerable is sorted?

One example of such method could be: static bool IsSorted<T>(IEnumerable<T> enumerable) where T : IComparable<T> { T prev = default(T); bool prevSet = false; foreach (var item in enumerable) { if (prevSet && (prev == null || prev.CompareTo(item) > 0)) return false; prev = item; prevSet = true; } return true; } Works with most … Read more

[Solved] parse and sort links [closed]

You can do it just by extracting the domain and using it as index for an array with the encrypted values, like so: $url=$_POST[‘url’]; $url=nl2br($url); $url=explode(“<br />”,$url); $urls = array(); foreach ($url as $value ){ $arr = explode(‘www.’,$value); $encrypt = md5($value); $urls[$arr[1]][]= $encrypt; //this line now fixed, had an error } foreach($urls as $key => … Read more

[Solved] why doesn’t my sorted code work in c? [closed]

#include <stdio.h> #include <stdlib.h> struct node { int data; struct node *nextPtr; }; struct node *firstPtr = NULL; void insertioon (int d){ struct node *np, *temp, *prev = NULL; int found; np=malloc(sizeof(struct node)); np->data = d; np->nextPtr = NULL; temp=firstPtr; found=0; while ((temp != NULL) && !found) { if (temp->data <d) { prev = temp; … Read more

[Solved] PHP sort array of arrays with key value

Try below code, I hope it is helpful. PHP Script. <?php // Static array. $array=array(); $array[0]=array( ‘_id’=>’5911af8209ed4456d069b1d3’, ‘title’=>’Zen M4S(Silver) 1’, ‘srp’=>1900 ); $array[1]=array( ‘_id’=>’5911af8209ed4456d069b1d2’, ‘title’=>’Zen M4S(Silver) 2’, ‘srp’=>1000 ); $array[2]=array( ‘_id’=>’5911af8209ed4456d069b1d4’, ‘title’=>’Zen M4S(Silver) 1’, ‘srp’=>1250 ); // For acending sorting. function asc_sort_json($array1,$array2){ $on = ‘srp’; if ($array1[$on] == $array2[$on]) { return 0; } return ($array1[$on] … Read more