Professional Documents
Culture Documents
LAB 2 Practice Tasks
LAB 2 Practice Tasks
functions:
1) Sequential insert in the list on the basis of Book_id
2) Sequential delete in the list and then adjust the list afterwards
3) Insert a value at a specific index and adjust remaining list afterwards
4) Delete a value at a specific index and adjust remaining list afterwards
5) Show all values present in the list
6) Show the length of the list
#include <iostream>
#include <string>
struct Book {
string title;
string author;
float price;
int book_id;
Book* next;
};
class BookList {
private:
Book* head;
public:
BookList() {
head = nullptr;
}
if (current == nullptr) {
cout << "Book not found." << endl;
return;
}
if (prev == nullptr) {
head = current->next;
} else {
prev->next = current->next;
}
delete current;
}
if (index == 0) {
Book* temp = head;
head = head->next;
delete temp;
} else {
Book* current = head;
for (int i = 0; i < index - 1 && current->next != nullptr; ++i) {
current = current->next;
}
if (current->next == nullptr) {
cout << "Index out of range." << endl;
return;
}
Book* temp = current->next;
current->next = current->next->next;
delete temp;
}
}
void display() {
Book* current = head;
while (current != nullptr) {
cout << "Book ID: " << current->book_id << ", Title: " << current->title << ", Author: "
<< current->author << ", Price: " << current->price << endl;
current = current->next;
}
}
int length() {
int count = 0;
Book* current = head;
while (current != nullptr) {
count++;
current = current->next;
}
return count;
}
};
int main() {
BookList books;
#include <iostream>
#include <string>
struct Employee {
string name;
int empNo;
float experience;
string designation;
float salary;
};
numEmployees++;
}
int main() {
const int MAX_EMPLOYEES = 100;
Employee employees[MAX_EMPLOYEES];
int numEmployees = 0;
char choice;
do {
addEmployee(employees, numEmployees);
cout << "Do you want to add another employee? (y/n): ";
cin >> choice;
} while (choice == 'y' || choice == 'Y');
cout << endl;
displayEmployees(employees, numEmployees);
sortEmployees(employees, numEmployees);
return 0;
}