Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
filter distinct items from the array without builtin function - Seeni
//Rextester.Program.Main is the entry point for your code. Don't change it. //Microsoft (R) Visual C# Compiler version 2.9.0.63208 (958f2354) using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { static HashSet<int> dupValues=new HashSet<int>(); public static void InsertDupVal(int arrVal) { Program.dupValues.Add(arrVal); } public static void processDistinctElements(int[] arr) { int n = arr.Length; for (int i = 0; i < n; i++) { for (int j = i+1; j < n; j++) { if (arr[i] == arr[j]) { InsertDupVal(arr[j]); } } } } public static void Main(string[] args) { //Write a program to filter distinct items from the array //array = [1,4,2,5,4,2,5,1,6,2,5,3,8,9,6] //Builtin array functions and LINQ are not allowed. Console.WriteLine("Start here..."); int[] nums = { 1, 4, 2, 5, 4, 2, 5, 1, 6, 2, 5, 3, 8, 9, 6 }; Program.processDistinctElements(nums); foreach (var d in Program.dupValues) { Console.WriteLine(d); } } } }
run
|
edit
|
history
|
help
0
Programmer DNA
hola1
makingNum
Action<> usage example
GYT
fgtyhi8uy7htr4e3qwcedf
up casting down casting
3
xml
adxsadxsd