Lab 3 Array Functions
Lab 3 Array Functions
S202432016
DSA LAB
#include <iostream>
using namespace std;
class Array {
private:
int arr[10]={1,2,3,4,5,6,7,8,9,10}; // Array with fixed size
int size = 10; // Current number of elements in the array
public:
// Constructor to initialize array elements and size
Array() {
int condition = 0;
for (int i = 0 ; i < 10 ; i++){
if (arr[i]== target ){
cout << "Target found at " << i << " Index";
condition = 1 ;
break;
}
}
if (condition == 0){
cout << "Target Not Found " ;
}
cout << "Enter the position to insert (0 to " << size << "):
";
cin >> position;
arr[position] = value;
size++;
}
}
}
int newArr[10];
int newSize = 0;
int main() {
Array array;
int choice;
do {
cout << "\nOperations:\n";
cout << "1. Traverse\n";
cout << "2. Search\n";
cout << "3. Insert\n";
cout << "4. Update\n";
cout << "5. Delete\n";
cout << "6. Sort\n";
cout << "7. Exit\n";
cout << "Enter your choice: ";
cin >> choice;
switch (choice) {
case 1:
array.traverse();
break;
case 2:
array.search();
break;
case 3:
array.insert();
break;
case 4:
array.update();
break;
case 5:
array.remove();
break;
case 6:
array.sort();
break;
case 7:
cout << "Exiting program." << endl;
break;
default:
cout << "Invalid choice! Try again." << endl;
}
} while (choice != 6);
return 0;
}
OUTPUTS:
1.
2.
3.
4.
5.
6.