RadixSort CRUD Documentation
RadixSort CRUD Documentation
Program Documentation
Overview
This C++ program demonstrates the use of radix sort for sorting an array of integers and
provides a simple CRUD (Create, Read, Update, Delete) interface for managing a database of
numbers. The program allows the user to:
- Create numbers and add them to the database.
- Read and display all numbers in the database.
- Update an existing number in the database.
- Delete a number from the database.
#include <iostream>
#include <vector>
#include <algorithm>
Global Variables
- `countSort` performs counting sort on the array `arr` based on the digit represented by
`pos`.
- `pos` determines which digit (units, tens, hundreds, etc.) is used for sorting.
- `output` stores the sorted array temporarily.
- `count` array keeps track of the count of each digit (0-9).
- `radixSort` sorts the array `arr` using the counting sort for each digit.
- `k` is the maximum number in the array, which determines the number of digits.
- The loop calls `countSort` for each digit position (units, tens, hundreds, etc.).
void readNumbers() {
cout << "Number Database:" << endl;
for (vector<int>::iterator it = database.begin(); it!= database.end(); ++it) {
cout << *it << " ";
}
cout << endl;
}
- `updateNumber` searches for `oldNum` in the `database` and replaces it with `newNum`.
Main Function
int main() {
int n;
cout << "Enter the number of numbers: ";
cin >> n;
radixSort(database);
while (true) {
cout << "CURD Operations:" << endl;
cout << "1. Create Number" << endl;
cout << "2. Read Numbers" << endl;
cout << "3. Update Number" << endl;
cout << "4. Delete Number" << endl;
cout << "5. Exit" << endl;
cout << "Enter your choice: ";
int choice;
cin >> choice;
switch (choice) {
case 1:
cout << "Enter number: ";
int num;
cin >> num;
createNumber(num);
break;
case 2:
readNumbers();
break;
case 3:
cout << "Enter old number: ";
int oldNum;
cin >> oldNum;
cout << "Enter new number: ";
int newNum;
cin >> newNum;
updateNumber(oldNum, newNum);
break;
case 4:
cout << "Enter number to delete: ";
int delNum;
cin >> delNum;
deleteNumber(delNum);
break;
case 5:
return 0;
}
}
return 0;
}
- The `main` function starts by asking the user to input the number of elements and the
elements themselves, which are added to the `database`.
- It then sorts the `database` using `radixSort`.
- An infinite loop provides a menu for CRUD operations:
1. **Create Number**: Adds a new number to the database.
2. **Read Numbers**: Displays all numbers in the database.
3. **Update Number**: Updates an existing number in the database.
4. **Delete Number**: Deletes a number from the database.
5. **Exit**: Exits the program.
Summary
This program allows the user to manage a database of integers with CRUD operations and
uses radix sort to sort the database. It provides a simple and interactive console interface
for managing and displaying the sorted list of numbers.