update
This commit is contained in:
parent
2992f4f408
commit
4f46de8d00
3330 changed files with 394553 additions and 76939 deletions
94
.config/Code/User/History/477921d5/yPV0.cpp
Normal file
94
.config/Code/User/History/477921d5/yPV0.cpp
Normal file
|
@ -0,0 +1,94 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
//class template
|
||||
template <typename T>
|
||||
class List{
|
||||
private:
|
||||
T* list; // Dynamic array to store the list elements
|
||||
int capacity; // Maximum capacity of the list
|
||||
int length; // Current number of elements in the list
|
||||
|
||||
void resize(){
|
||||
// Resize the array to double its current size
|
||||
T* newList = new T[capacity * 2];
|
||||
for (int i = 0; i < length; i++) {
|
||||
newList[i] = list[i];
|
||||
}
|
||||
delete[] list;
|
||||
list = newList;
|
||||
capacity *= 2;
|
||||
}
|
||||
|
||||
public:
|
||||
// Constructor to initialize the list with a fixed capacity
|
||||
List(int initialSize = 100){
|
||||
capacity = initialSize;
|
||||
list = new T[capacity];
|
||||
length = 0;
|
||||
}
|
||||
|
||||
// Destructor to free the dynamically allocated memory
|
||||
~List(){
|
||||
delete[] list;
|
||||
}
|
||||
|
||||
// Insert an element at a specific position (0-based index)
|
||||
void insert(int position, T value){
|
||||
|
||||
// write code
|
||||
}
|
||||
|
||||
// Delete an element by its value (first occurrence)
|
||||
bool deleteByValue(T value){
|
||||
|
||||
// write code
|
||||
}
|
||||
|
||||
// Delete an element by its position (0-based index)
|
||||
bool deleteByPosition(int position){
|
||||
|
||||
// write code
|
||||
|
||||
}
|
||||
|
||||
// Search for an element by its value, return the position if found, otherwise -1
|
||||
int search(T value){
|
||||
|
||||
// write code
|
||||
}
|
||||
|
||||
// Access an element by its position (0-based index)
|
||||
T access(int position){
|
||||
|
||||
// write code
|
||||
|
||||
}
|
||||
|
||||
// Return the current number of elements in the list
|
||||
int size(){
|
||||
|
||||
// write code
|
||||
}
|
||||
|
||||
// Check if the list is empty
|
||||
bool isEmpty(){
|
||||
|
||||
// write code
|
||||
}
|
||||
|
||||
// Display the elements of the list
|
||||
void display(){
|
||||
|
||||
// write code
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
int main() {
|
||||
|
||||
// write code to test functionalities
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue