Answers for "Linear search dart"

0

Linear search dart

void linearSearch(int key) {
    bool isExist = false;
    for (var i = 0; i < list.length; i++) {
      if (list[i] == key) {
        print("The item ${list[i]} is exist and it's index is $i");
        isExist = true;
        return;
      }
    }
    if (!isExist) {
      print("Not found");
    }
  }
Posted by: Guest on January-23-2022

Code answers related to "Dart"

Browse Popular Code Answers by Language