Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
normalised pagination
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static int[] GetThumbs(int fromInt, int num) { int[] t = new int[num]; int v = fromInt; for (int x=0;x<num;x++){ t[x]=v; v++; } return t; } public static void PrintThumb(int[] t) { for(int x=0; x<t.Length;x++){ Console.Write("{0};",t[x]); } } public static void PrintPages(int[][] p) { for(int x=0; x<p.Length;x++){ Console.Write("Page {0}; ", x+1); PrintThumb(p[x]); Console.WriteLine("\n"); } } public static int[][] pages = {}; public static void GeneratePages(int amount, int thumbsPerPage) { pages = new int[amount][]; int offset=1; for(int i=0; i < amount; i++){ pages[i] = GetThumbs(offset, thumbsPerPage); offset += thumbsPerPage; } } public static int[] Pagination(int[][] dataset, int page, int thumbPerPage, int targetThumbPerPage) { int record = page * thumbPerPage; float targetPageWithOffset = record / (float)targetThumbPerPage; float targetOffset = (targetPageWithOffset - (int)targetPageWithOffset); float targetPageOffset = targetOffset * targetThumbPerPage; int[] modDataset = new int[thumbPerPage]; int count=0; for(int p=(int)targetPageWithOffset; p < dataset.Length;p++) { for(int o=(int)targetPageOffset; o < targetThumbPerPage; o++){ if (count >= modDataset.Length) { return modDataset; } modDataset[count] = dataset[p][o]; count++; } targetPageOffset = 0; } return modDataset; } public static void TransformPages(int[][] dataset, int printPages, int thumbPerPage, int targetThumbPerPage) { for(int i=0; i < printPages; i++){ Console.Write("Page {0}; ", i+1); PrintThumb(Pagination(pages, i, thumbPerPage, targetThumbPerPage)); Console.WriteLine("\n"); } } public static void Main(string[] args) { // Generate 100 pages with 25 thumbsnails per page. GeneratePages(10, 25); Console.WriteLine("Original"); PrintPages(pages); // "fetch" 5 pages with 35 thumbs per page when target source is 25 thumbs per page. Console.WriteLine("Transformed"); TransformPages(pages, 5, 25, 25); } } }
run
|
edit
|
history
|
help
1
Bubble Sort
asxsdxsdf
COMPLEX NUMBER
Finding occurances of a value in the elements of a list
enums with extension method: better
asxsd dxsd
axasxasxasaxsd
Bases5
Overriding fields
QLSV