CPSC270A
Software Eng & Project Design

Activity 3

Sort with Dart

Write a dart program that sorts a list of ints.

Details

The progam should:

  1. read a list of ints from the user.

  2. sort the list of ints from lowest to highest. It should not use the built-in sort, min, or max functions.

  3. print the sorted list of ints.

The following program is an example of command line input and output using dart:

import 'dart:io';

void main(){
  print("Enter a number: ");
  var userInputString = stdin.readLineSync();
  var userInputInt = int.parse(userInputString);
  var doubleUserInput = userInputInt + userInputInt;
  print("$userInputInt + $userInputInt = $doubleUserInput\n");
}

Example

How many numbers?: 3
Enter a number: 5
Enter a number: -1
Enter a number: 2
The numbers sorted are: [-1, 2, 5]