GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Java/java-combinations/src/main/java/com/hmkcode/Shifting.java at master · Fruso/Java Expand file tree/ Copy pathShifting.javaMore file actions 66 lines (54 loc) · 1.45 KB / Copy pathShifting.javaFile metadata and controls66 lines (54 loc) · 1.45 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 package com.hmkcode; public class Shifting { public static void main( String[] args ) { String[] e = {"A","B","C","D","E"}; int k = 3; combination(e,k); } public static void combination(Object[] e, int k){ int[] ignore = new int[e.length-k]; // --> [0][0] int[] combination = new int[k]; // --> [][][] // set initial ignored elements //(last k elements will be ignored) for(int w = 0; w < ignore.length; w++) ignore[w] = e.length - k +(w+1); int i = 0, r = 0, g = 0; boolean terminate = false; while(!terminate){ // selecting N-k non-ignored elements while(i < e.length && r < k){ if(i != ignore[g]){ combination[r] = i; r++; i++; } else{ if(g != ignore.length-1) g++; i++; } } print(combination, e); i = 0; r = 0; g = 0; terminate = true; // shifting ignored indices for(int w = 0 ; w < ignore.length; w++){ if(ignore[w] > w){ ignore[w]--; if(w > 0) ignore[w-1] = ignore[w]-1; terminate = false; break; } } } } private static void print(int[] combination, Object[] elements){ String output = ""; for(int z = 0 ; z < combination.length;z++){ output += elements[combination[z]]; } System.out.println(output); } } |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |