Array List object

Revise this code example C# for Finding the duplicates and follow the discussion question below. Apart from code, the writing part is just 150 words

 

//function to display the duplicate values in an Array  public void Display Array(ArrayList ary)

{ //loop through all the elements  for (int i = 0; i < ary.Count; i++)

{Console.Write(ary[i]+” “); }  Console.WriteLine(); }

//function to find the duplicate values in an Array public void Find Duplicate(ArrayList ary)

{ //Array list to store all the duplicate values  ArrayList dup = new ArrayList(); for (int i = 0; i < ary.Count;i++)

{ for (int j =i+1; j < ary.Count; j++) { //compare each value with following remaining values  if (ary[i].Equals(ary[j]))

{ //When duplicate value is found, check //whether the value not contained in the dup array list   if(!dup.Contains(ary[i]))

{ //if not contains, then add the value to dup array list  dup.Add(ary[i]);   }}} }

Console.WriteLine(“The numbers which duplicates are”);    DisplayArray(dup); } //Input Arraylist values: 4,5,2,5,4,7 Output: 4 5 2 5 4 7 The numbers which are duplicates: 4 5

DISCUSSION TOPICS

After reading week 2 required materials and conducting independent research as needed, discuss with your peers the following:

  • The solution uses an ArrayList object. Modify it and make it run with code that uses a different approach to solve the problem with identical results:
  1. Post an alternative solution(it must run on Visual Studio)
  2. Explain what is different and how it works
  3. Compare the ArrayList approach with the alternative solution, evaluate which one is more effective, and explain why.