Recap - List Organizer
Part of the Logic & Flow section of Coddy's Dart journey — lesson 9 of 65.
Challenge
EasyCreate a program that manages a data processing pipeline by performing multiple operations on a list of numbers in sequence. Your program should:
- Read a string input representing the dataset name
- Read multiple integer inputs representing the original data values (the input will end when you receive
-999) - Insert the value
100at the beginning of the list (position 0) - Remove all negative numbers from the list using
removeWhere() - Sort the remaining numbers in ascending order using
sort() - Check if the final list is empty using
isEmpty - 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 remainingIf 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 remainingIf 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 remainingYour 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
1Advanced List Manipulation
List Properties: first & lastList State: isEmpty & isNotEmpReversing a ListAdding to a List: insertList Removal: removeWhereFinding in a List: indexOfSorting a ListShuffling a ListRecap - List Organizer4Advanced Map Manipulation
Iterating Over a MapChecking for Keys and ValuesMap Properties: keys & valuesConditional Add: putIfAbsentRemoving Entries from a MapNested MapsRecap - Inventory Update2Functional List Operations
Transforming with 'map'Filtering with 'where'Using '.toList()'Checking Conditions with 'any'Conditions with 'every'Finding with 'firstWhere'Recap - Data Filtering5Project: Shopping Cart Calc
Project SetupAdding Items to the Cart3Sets
What is a Set?Creating a SetAdding and Removing from SetsChecking for Elements in a SetConverting a List to a SetSet UnionSet IntersectionSet DifferenceRecap - Unique Guest List