Lecture4 code

# Lecture4 code - { if (a[j] &amp;amp;lt; a[i]) //Swap a[i]...

This preview shows pages 1–2. Sign up to view the full content.

Lecture 4 code using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace Simple_sort { public partial class Form1 : Form { int [] a; public Form1() { InitializeComponent(); } private void btnSort_Click(object sender, EventArgs e) { int n, temp; n = getA(); //Get array values from form for (int i = 0; i < n - 1; i++) //Find smallest a[i] { for (int j = i + 1; j < n; j++) //Compare with "remaining" elements

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: { if (a[j] &lt; a[i]) //Swap a[i] and a[j] if a[j] is smaller { temp = a[i]; a[i] = a[j]; a[j] = temp; } } } writeResults(n); //Put sorted elements on form } private void writeResults(int n) { rtbResults.Text = &quot;&quot;; for (int i = 0; i &lt; n; i++) { rtbResults.Text += a[i] + &quot;\n&quot;; } } private int getA() { int ret = 0; ret = rtbArray.Lines.Length; a = new int[ret]; for (int i = 0; i &lt; ret; i++) a[i] = Convert.ToInt32(rtbArray.Lines [i].ToString ()); return ret; } } }...
View Full Document

## Lecture4 code - { if (a[j] &amp;amp;lt; a[i]) //Swap a[i]...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online