Menu
Coddy logo textTech

Recap - List Organizer

Part of the Logic & Flow section of Coddy's Dart journey — lesson 9 of 65.

challenge icon

Challenge

Easy

Create a program that manages a data processing pipeline by performing multiple operations on a list of numbers in sequence. Your program should:

  1. Read a string input representing the dataset name
  2. Read multiple integer inputs representing the original data values (the input will end when you receive -999)
  3. Insert the value 100 at the beginning of the list (position 0)
  4. Remove all negative numbers from the list using removeWhere()
  5. Sort the remaining numbers in ascending order using sort()
  6. Check if the final list is empty using isEmpty
  7. Print the data processing results in the exact format shown below

For example, if the dataset name is "Sales Data" and the values are 45, -12, 78, -5, 23, your program should output:

Dataset: Sales Data
Original data: [45, -12, 78, -5, 23]
Step 1: Inserted 100 at beginning
After insertion: [100, 45, -12, 78, -5, 23]
Step 2: Removed negative numbers
After removal: [100, 45, 78, 23]
Step 3: Sorted in ascending order
After sorting: [23, 45, 78, 100]
Final result: List is not empty
Processing complete: 4 values remaining

If the dataset name is "Temperature Readings" and the values are -10, -5, -20, your program should output:

Dataset: Temperature Readings
Original data: [-10, -5, -20]
Step 1: Inserted 100 at beginning
After insertion: [100, -10, -5, -20]
Step 2: Removed negative numbers
After removal: [100]
Step 3: Sorted in ascending order
After sorting: [100]
Final result: List is not empty
Processing complete: 1 values remaining

If the dataset name is "Error Values" and the only value is -50, your program should output:

Dataset: Error Values
Original data: [-50]
Step 1: Inserted 100 at beginning
After insertion: [100, -50]
Step 2: Removed negative numbers
After removal: [100]
Step 3: Sorted in ascending order
After sorting: [100]
Final result: List is not empty
Processing complete: 1 values remaining

Your program must perform all operations in the exact sequence specified: first insert() the value 100 at position 0, then use removeWhere() to remove negative numbers, then sort() the list, and finally check if the list isEmpty. Display "List is empty" if the final list has no elements, or "List is not empty" if it contains elements.

Try it yourself

import 'dart:io';

void main() {
  // Read dataset name
  String? datasetName = stdin.readLineSync();
  
  // Read numbers until -999 is encountered
  List<int> originalData = [];
  while (true) {
    int? number = int.parse(stdin.readLineSync()!);
    if (number == -999) {
      break;
    }
    originalData.add(number);
  }
  
  // Print initial information
  print('Dataset: $datasetName');
  print('Original data: $originalData');
  
  // TODO: Write your code below
  // 1. Insert 100 at the beginning (position 0)
  // 2. Remove all negative numbers using removeWhere()
  // 3. Sort the list in ascending order using sort()
  // 4. Check if the list is empty using isEmpty
  // 5. Print the results in the required format
  
}

All lessons in Logic & Flow