100% Guaranteed Results


Advance Csharp – Exercise: Arrays, Lists, Stacks, Queues Solved
$ 24.99
Category:

Description

5/5 – (1 vote)

Problem 1. Sort Array of Numbers Using Bubble Sort
Write a program to sort an array of integer numbers and then print them back on the console. The numbers should be entered from the console on a single line, separated by a space. Print the sorted array in the following format: “[element1, element2… elementN]”.
Condition: Do not use the built-in sorting method, you should write the logic yourself. Use the bubble sort algorithm.
Step 1. Read and Process the Input
Step 2. Search the Algorithm and Understand How It Works
Bubble sort is a very simple sorting algorithm. At each step, two consecutive elements in the array are compared and if the second one is smaller than the first the elements are swapped (they exchange places). The process continues until all elements are sorted – an entire iteration has passed without a swap occurring.
Step 3. Implement the Algorithm
Step 4. Print the Result
Test your program with different inputs to make sure it works as intended.

Problem 2. Join Lists
Write a program that takes as input two lists of integers and joins them. The result should hold all numbers from the first list, and all numbers from the second list, without repeating numbers, and arranged in increasing order. The input and output lists are given as integers, separated by a space, each list at a separate line. Do not use LINQ! This problems aims to help you exercise your algorithmic thinking and not how well you are familiar with built-in .NET functionalities. Use only arrays and lists. Examples:
Input Output
20 40 10 10 30 80
25 20 40 30 10 10 20 25 30 40 80
5 4 3 2 1
6 3 2 1 2 3 4 5 6
1
1 1
Step 1. Read and Process the Input
As with the first problem, the first step is to take the input numbers and store them in two separate sets (arrays or lists).
Step 2. Create a New List to Hold the Result
You can’t know for sure how many numbers will be found in the two sets. Instead of creating an array with a fixed size (e.g. the combined size of both sets), a much better approach is to use a List<int>. There are better choices for this particular problem (SortedSet<T> will be covered in the next lecture), but then it would be too easy, wouldn’t it?
Step 3. Fill the List by Iterating the Sets
Iterate each set and if the current element is not already in the resulting list – add it. If the number is already present, there is no need to add it (you would need to filter out repeating numbers afterwards which is unnecessary).
Step 4. Sort the List and Print It
Remember to test your program! It is recommended that you perform manual tests at each step of the process and not just at the very end. This is how you solve much more complex problems.

Reviews

There are no reviews yet.

Be the first to review “Advance Csharp – Exercise: Arrays, Lists, Stacks, Queues Solved”

Your email address will not be published. Required fields are marked *

Related products