update
This commit is contained in:
parent
2992f4f408
commit
4f46de8d00
3330 changed files with 394553 additions and 76939 deletions
99
.config/Code/User/History/477921d5/1SOp.cpp
Normal file
99
.config/Code/User/History/477921d5/1SOp.cpp
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
#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){
|
||||
if(length >= capacity) resize();
|
||||
|
||||
for(int i=length;i>=position;i--){
|
||||
list[i+1] = list[i];
|
||||
}
|
||||
list[position] = value;
|
||||
length++;
|
||||
}
|
||||
|
||||
// Delete an element by its value (first occurrence)
|
||||
bool deleteByValue(T value){
|
||||
|
||||
}
|
||||
|
||||
// Delete an element by its position (0-based index)
|
||||
bool deleteByPosition(int position){
|
||||
for(int i=position;i<length;i++){
|
||||
list[i] = list[i+1];
|
||||
}
|
||||
length--;
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
99
.config/Code/User/History/477921d5/AFXm.cpp
Normal file
99
.config/Code/User/History/477921d5/AFXm.cpp
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
#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){
|
||||
if(length >= capacity) resize();
|
||||
else{
|
||||
for(int i=length;i>=position;i--){
|
||||
list[i+1] = list[i];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
94
.config/Code/User/History/477921d5/BXir.cpp
Normal file
94
.config/Code/User/History/477921d5/BXir.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){
|
||||
|
||||
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
113
.config/Code/User/History/477921d5/FgtM.cpp
Normal file
113
.config/Code/User/History/477921d5/FgtM.cpp
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
#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){
|
||||
if(position > length) return;
|
||||
if(length >= capacity) resize();
|
||||
|
||||
for(int i=length;i>=position;i--){
|
||||
list[i+1] = list[i];
|
||||
}
|
||||
list[position] = value;
|
||||
length++;
|
||||
}
|
||||
|
||||
// Delete an element by its value (first occurrence)
|
||||
bool deleteByValue(T value){
|
||||
int index = search(value);
|
||||
return deleteByPosition(index);
|
||||
}
|
||||
|
||||
// Delete an element by its position (0-based index)
|
||||
bool deleteByPosition(int position){
|
||||
if(position > length) return false;
|
||||
else{
|
||||
for(int i=position;i<length;i++){
|
||||
list[i] = list[i+1];
|
||||
}
|
||||
length--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Search for an element by its value, return the position if found, otherwise -1
|
||||
int search(T value){
|
||||
for(int i=0;i<length;i++){
|
||||
if(list[i] == value) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Access an element by its position (0-based index)
|
||||
T access(int position){
|
||||
return list[position];
|
||||
}
|
||||
|
||||
// Return the current number of elements in the list
|
||||
int size(){
|
||||
return length;
|
||||
}
|
||||
|
||||
// Check if the list is empty
|
||||
bool isEmpty(){
|
||||
return length == 0;
|
||||
}
|
||||
|
||||
// Display the elements of the list
|
||||
void display(){
|
||||
for(int i=0;i<length;i++){
|
||||
cout<<list[i]<<" ";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
int main(){
|
||||
|
||||
List<int> list;
|
||||
list.insert(0, 10);
|
||||
list.insert(0, 13);
|
||||
list.insert(0, 11);
|
||||
list.insert(0, 16);
|
||||
list.deleteByPosition(3);
|
||||
list.deleteByValue(16);
|
||||
cout<<list.isEmpty()<<endl;
|
||||
list.display();
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
94
.config/Code/User/History/477921d5/O1PV.cpp
Normal file
94
.config/Code/User/History/477921d5/O1PV.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;
|
||||
}
|
||||
|
||||
110
.config/Code/User/History/477921d5/TPZO.cpp
Normal file
110
.config/Code/User/History/477921d5/TPZO.cpp
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
#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){
|
||||
if(position > length) return;
|
||||
if(length >= capacity) resize();
|
||||
|
||||
for(int i=length;i>=position;i--){
|
||||
list[i+1] = list[i];
|
||||
}
|
||||
list[position] = value;
|
||||
length++;
|
||||
}
|
||||
|
||||
// Delete an element by its value (first occurrence)
|
||||
bool deleteByValue(T value){
|
||||
int index = search(value);
|
||||
return deleteByPosition(index);
|
||||
}
|
||||
|
||||
// Delete an element by its position (0-based index)
|
||||
bool deleteByPosition(int position){
|
||||
if(position > length) return false;
|
||||
else{
|
||||
for(int i=position;i<length;i++){
|
||||
list[i] = list[i+1];
|
||||
}
|
||||
length--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Search for an element by its value, return the position if found, otherwise -1
|
||||
int search(T value){
|
||||
for(int i=0;i<length;i++){
|
||||
if(list[i] == value) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Access an element by its position (0-based index)
|
||||
T access(int position){
|
||||
return list[position];
|
||||
}
|
||||
|
||||
// Return the current number of elements in the list
|
||||
int size(){
|
||||
return length;
|
||||
}
|
||||
|
||||
// Check if the list is empty
|
||||
bool isEmpty(){
|
||||
return length == 0;
|
||||
}
|
||||
|
||||
// Display the elements of the list
|
||||
void display(){
|
||||
for(int i=0;i<length;i++){
|
||||
cout<<list[i]<<" ";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
int main(){
|
||||
|
||||
List<int> list;
|
||||
list.insert(0, 10);
|
||||
list.insert(0, 13);
|
||||
list.insert(0, 11);
|
||||
list.insert(0, 16);
|
||||
list.display();
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
99
.config/Code/User/History/477921d5/XJNJ.cpp
Normal file
99
.config/Code/User/History/477921d5/XJNJ.cpp
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
#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){
|
||||
if(length >= capacity) resize();
|
||||
else{
|
||||
for(int i=length;i>position;i--){
|
||||
list[i+1] = list[i];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
94
.config/Code/User/History/477921d5/Z5dl.cpp
Normal file
94
.config/Code/User/History/477921d5/Z5dl.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;
|
||||
}
|
||||
|
||||
107
.config/Code/User/History/477921d5/cOpD.cpp
Normal file
107
.config/Code/User/History/477921d5/cOpD.cpp
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
#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){
|
||||
if(position > length) return;
|
||||
if(length >= capacity) resize();
|
||||
|
||||
for(int i=length;i>=position;i--){
|
||||
list[i+1] = list[i];
|
||||
}
|
||||
list[position] = value;
|
||||
length++;
|
||||
}
|
||||
|
||||
// Delete an element by its value (first occurrence)
|
||||
bool deleteByValue(T value){
|
||||
int index = search(value);
|
||||
return deleteByPosition(index);
|
||||
}
|
||||
|
||||
// Delete an element by its position (0-based index)
|
||||
bool deleteByPosition(int position){
|
||||
if(position > length) return false;
|
||||
else{
|
||||
for(int i=position;i<length;i++){
|
||||
list[i] = list[i+1];
|
||||
}
|
||||
length--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Search for an element by its value, return the position if found, otherwise -1
|
||||
int search(T value){
|
||||
for(int i=0;i<length;i++){
|
||||
if(list[i] == value) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Access an element by its position (0-based index)
|
||||
T access(int position){
|
||||
return list[position];
|
||||
}
|
||||
|
||||
// Return the current number of elements in the list
|
||||
int size(){
|
||||
return length;
|
||||
}
|
||||
|
||||
// Check if the list is empty
|
||||
bool isEmpty(){
|
||||
return length == 0;
|
||||
}
|
||||
|
||||
// Display the elements of the list
|
||||
void display(){
|
||||
for(int i=0;i<length;i++){
|
||||
cout<<list[i]<<" ";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
int main(){
|
||||
|
||||
List<int> list;
|
||||
list.insert(0, 10);
|
||||
list.display();
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
1
.config/Code/User/History/477921d5/entries.json
Normal file
1
.config/Code/User/History/477921d5/entries.json
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"version":1,"resource":"file:///home/rafayahmad/Stuff/Coding/C%2B%2B/DS/lab3/q1.cpp","entries":[{"id":"Z5dl.cpp","timestamp":1725877236082},{"id":"yPV0.cpp","timestamp":1725877256339},{"id":"O1PV.cpp","timestamp":1725877288012},{"id":"BXir.cpp","timestamp":1725877305672},{"id":"XJNJ.cpp","timestamp":1725877419611},{"id":"AFXm.cpp","timestamp":1725877432528},{"id":"xrBq.cpp","timestamp":1725877470344},{"id":"1SOp.cpp","timestamp":1725877505577},{"id":"vK6x.cpp","timestamp":1725877605610},{"id":"sf12.cpp","timestamp":1725877664766},{"id":"yD2s.cpp","timestamp":1725877722179},{"id":"viJK.cpp","timestamp":1725880239736},{"id":"zSCD.cpp","timestamp":1725881002460},{"id":"vllg.cpp","timestamp":1725881046951},{"id":"cOpD.cpp","timestamp":1725881060081},{"id":"TPZO.cpp","timestamp":1725881086715},{"id":"FgtM.cpp","timestamp":1725881120919},{"id":"l9K2.cpp","timestamp":1725881141893},{"id":"kyl8.cpp","timestamp":1725881179657},{"id":"mfsZ.cpp","timestamp":1725881201370},{"id":"mIyz.cpp","timestamp":1725881456126}]}
|
||||
115
.config/Code/User/History/477921d5/kyl8.cpp
Normal file
115
.config/Code/User/History/477921d5/kyl8.cpp
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
#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){
|
||||
if(position > length) return;
|
||||
if(length >= capacity) resize();
|
||||
|
||||
for(int i=length;i>=position;i--){
|
||||
list[i+1] = list[i];
|
||||
}
|
||||
list[position] = value;
|
||||
length++;
|
||||
}
|
||||
|
||||
// Delete an element by its value (first occurrence)
|
||||
bool deleteByValue(T value){
|
||||
int index = search(value);
|
||||
return deleteByPosition(index);
|
||||
}
|
||||
|
||||
// Delete an element by its position (0-based index)
|
||||
bool deleteByPosition(int position){
|
||||
if(position > length) return false;
|
||||
else{
|
||||
for(int i=position;i<length;i++){
|
||||
list[i] = list[i+1];
|
||||
}
|
||||
length--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Search for an element by its value, return the position if found, otherwise -1
|
||||
int search(T value){
|
||||
for(int i=0;i<length;i++){
|
||||
if(list[i] == value) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Access an element by its position (0-based index)
|
||||
T access(int position){
|
||||
return list[position];
|
||||
}
|
||||
|
||||
// Return the current number of elements in the list
|
||||
int size(){
|
||||
return length;
|
||||
}
|
||||
|
||||
// Check if the list is empty
|
||||
bool isEmpty(){
|
||||
return length == 0;
|
||||
}
|
||||
|
||||
// Display the elements of the list
|
||||
void display(){
|
||||
for(int i=0;i<length;i++){
|
||||
cout<<list[i]<<" ";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
int main(){
|
||||
|
||||
List<int> list;
|
||||
list.insert(0, 10);
|
||||
list.insert(0, 13);
|
||||
list.insert(0, 11);
|
||||
list.insert(0, 16);
|
||||
list.deleteByPosition(3);
|
||||
list.deleteByValue(16);
|
||||
cout<<list.isEmpty()<<endl;
|
||||
cout<<list.size()<<endl;
|
||||
cout<<list.search(13)<<endl;
|
||||
list.display();
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
114
.config/Code/User/History/477921d5/l9K2.cpp
Normal file
114
.config/Code/User/History/477921d5/l9K2.cpp
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
#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){
|
||||
if(position > length) return;
|
||||
if(length >= capacity) resize();
|
||||
|
||||
for(int i=length;i>=position;i--){
|
||||
list[i+1] = list[i];
|
||||
}
|
||||
list[position] = value;
|
||||
length++;
|
||||
}
|
||||
|
||||
// Delete an element by its value (first occurrence)
|
||||
bool deleteByValue(T value){
|
||||
int index = search(value);
|
||||
return deleteByPosition(index);
|
||||
}
|
||||
|
||||
// Delete an element by its position (0-based index)
|
||||
bool deleteByPosition(int position){
|
||||
if(position > length) return false;
|
||||
else{
|
||||
for(int i=position;i<length;i++){
|
||||
list[i] = list[i+1];
|
||||
}
|
||||
length--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Search for an element by its value, return the position if found, otherwise -1
|
||||
int search(T value){
|
||||
for(int i=0;i<length;i++){
|
||||
if(list[i] == value) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Access an element by its position (0-based index)
|
||||
T access(int position){
|
||||
return list[position];
|
||||
}
|
||||
|
||||
// Return the current number of elements in the list
|
||||
int size(){
|
||||
return length;
|
||||
}
|
||||
|
||||
// Check if the list is empty
|
||||
bool isEmpty(){
|
||||
return length == 0;
|
||||
}
|
||||
|
||||
// Display the elements of the list
|
||||
void display(){
|
||||
for(int i=0;i<length;i++){
|
||||
cout<<list[i]<<" ";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
int main(){
|
||||
|
||||
List<int> list;
|
||||
list.insert(0, 10);
|
||||
list.insert(0, 13);
|
||||
list.insert(0, 11);
|
||||
list.insert(0, 16);
|
||||
list.deleteByPosition(3);
|
||||
list.deleteByValue(16);
|
||||
cout<<list.isEmpty()<<endl;
|
||||
cout<<list.size()<<endl;
|
||||
list.display();
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
115
.config/Code/User/History/477921d5/mIyz.cpp
Normal file
115
.config/Code/User/History/477921d5/mIyz.cpp
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
#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){
|
||||
if(position > length) return;
|
||||
if(length >= capacity) resize();
|
||||
|
||||
for(int i=length;i>=position;i--){
|
||||
list[i+1] = list[i];
|
||||
}
|
||||
list[position] = value;
|
||||
length++;
|
||||
}
|
||||
|
||||
// Delete an element by its value (first occurrence)
|
||||
bool deleteByValue(T value){
|
||||
int index = search(value);
|
||||
return deleteByPosition(index);
|
||||
}
|
||||
|
||||
// Delete an element by its position (0-based index)
|
||||
bool deleteByPosition(int position){
|
||||
if(position > length) return false;
|
||||
else{
|
||||
for(int i=position;i<length;i++){
|
||||
list[i] = list[i+1];
|
||||
}
|
||||
length--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Search for an element by its value, return the position if found, otherwise -1
|
||||
int search(T value){
|
||||
for(int i=0;i<length;i++){
|
||||
if(list[i] == value) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Access an element by its position (0-based index)
|
||||
T access(int position){
|
||||
return list[position];
|
||||
}
|
||||
|
||||
// Return the current number of elements in the list
|
||||
int size(){
|
||||
return length;
|
||||
}
|
||||
|
||||
// Check if the list is empty
|
||||
bool isEmpty(){
|
||||
return length == 0;
|
||||
}
|
||||
|
||||
// Display the elements of the list
|
||||
void display(){
|
||||
for(int i=0;i<length;i++){
|
||||
cout<<list[i]<<" ";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
int main(){
|
||||
|
||||
List<int> list;
|
||||
list.insert(0, 10);
|
||||
list.insert(0, 13);
|
||||
list.insert(0, 11);
|
||||
list.insert(0, 16);
|
||||
list.deleteByPosition(3);
|
||||
list.deleteByValue(16);
|
||||
cout<<list.isEmpty()<<endl;
|
||||
cout<<list.size()<<endl;
|
||||
cout<<list.search(13)<<endl;
|
||||
cout<<list.access(0)<<endl;
|
||||
list.display();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
115
.config/Code/User/History/477921d5/mfsZ.cpp
Normal file
115
.config/Code/User/History/477921d5/mfsZ.cpp
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
#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){
|
||||
if(position > length) return;
|
||||
if(length >= capacity) resize();
|
||||
|
||||
for(int i=length;i>=position;i--){
|
||||
list[i+1] = list[i];
|
||||
}
|
||||
list[position] = value;
|
||||
length++;
|
||||
}
|
||||
|
||||
// Delete an element by its value (first occurrence)
|
||||
bool deleteByValue(T value){
|
||||
int index = search(value);
|
||||
return deleteByPosition(index);
|
||||
}
|
||||
|
||||
// Delete an element by its position (0-based index)
|
||||
bool deleteByPosition(int position){
|
||||
if(position > length) return false;
|
||||
else{
|
||||
for(int i=position;i<length;i++){
|
||||
list[i] = list[i+1];
|
||||
}
|
||||
length--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Search for an element by its value, return the position if found, otherwise -1
|
||||
int search(T value){
|
||||
for(int i=0;i<length;i++){
|
||||
if(list[i] == value) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Access an element by its position (0-based index)
|
||||
T access(int position){
|
||||
return list[position];
|
||||
}
|
||||
|
||||
// Return the current number of elements in the list
|
||||
int size(){
|
||||
return length;
|
||||
}
|
||||
|
||||
// Check if the list is empty
|
||||
bool isEmpty(){
|
||||
return length == 0;
|
||||
}
|
||||
|
||||
// Display the elements of the list
|
||||
void display(){
|
||||
for(int i=0;i<length;i++){
|
||||
cout<<list[i]<<" ";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
int main(){
|
||||
|
||||
List<int> list;
|
||||
list.insert(0, 10);
|
||||
list.insert(0, 13);
|
||||
list.insert(0, 11);
|
||||
list.insert(0, 16);
|
||||
list.deleteByPosition(3);
|
||||
list.deleteByValue(16);
|
||||
cout<<list.isEmpty()<<endl;
|
||||
cout<<list.size()<<endl;
|
||||
cout<<list.search(13)<<endl;
|
||||
cout<<list.access(0)<<endl;
|
||||
list.display();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
106
.config/Code/User/History/477921d5/sf12.cpp
Normal file
106
.config/Code/User/History/477921d5/sf12.cpp
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
#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){
|
||||
if(length >= capacity) resize();
|
||||
|
||||
for(int i=length;i>=position;i--){
|
||||
list[i+1] = list[i];
|
||||
}
|
||||
list[position] = value;
|
||||
length++;
|
||||
}
|
||||
|
||||
// Delete an element by its value (first occurrence)
|
||||
bool deleteByValue(T value){
|
||||
int index = search(value);
|
||||
deleteByPosition(index);
|
||||
}
|
||||
|
||||
// Delete an element by its position (0-based index)
|
||||
bool deleteByPosition(int position){
|
||||
if(position > length) return false;
|
||||
else{
|
||||
for(int i=position;i<length;i++){
|
||||
list[i] = list[i+1];
|
||||
}
|
||||
length--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Search for an element by its value, return the position if found, otherwise -1
|
||||
int search(T value){
|
||||
for(int i=0;i<length;i++){
|
||||
if(list[i] == value) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
102
.config/Code/User/History/477921d5/vK6x.cpp
Normal file
102
.config/Code/User/History/477921d5/vK6x.cpp
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
#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){
|
||||
if(length >= capacity) resize();
|
||||
|
||||
for(int i=length;i>=position;i--){
|
||||
list[i+1] = list[i];
|
||||
}
|
||||
list[position] = value;
|
||||
length++;
|
||||
}
|
||||
|
||||
// Delete an element by its value (first occurrence)
|
||||
bool deleteByValue(T value){
|
||||
|
||||
}
|
||||
|
||||
// Delete an element by its position (0-based index)
|
||||
bool deleteByPosition(int position){
|
||||
if(position > length) return false;
|
||||
else{
|
||||
for(int i=position;i<length;i++){
|
||||
list[i] = list[i+1];
|
||||
}
|
||||
length--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Search for an element by its value, return the position if found, otherwise -1
|
||||
int search(T value){
|
||||
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
104
.config/Code/User/History/477921d5/viJK.cpp
Normal file
104
.config/Code/User/History/477921d5/viJK.cpp
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
#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){
|
||||
if(length >= capacity) resize();
|
||||
|
||||
for(int i=length;i>=position;i--){
|
||||
list[i+1] = list[i];
|
||||
}
|
||||
list[position] = value;
|
||||
length++;
|
||||
}
|
||||
|
||||
// Delete an element by its value (first occurrence)
|
||||
bool deleteByValue(T value){
|
||||
int index = search(value);
|
||||
deleteByPosition(index);
|
||||
}
|
||||
|
||||
// Delete an element by its position (0-based index)
|
||||
bool deleteByPosition(int position){
|
||||
if(position > length) return false;
|
||||
else{
|
||||
for(int i=position;i<length;i++){
|
||||
list[i] = list[i+1];
|
||||
}
|
||||
length--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Search for an element by its value, return the position if found, otherwise -1
|
||||
int search(T value){
|
||||
for(int i=0;i<length;i++){
|
||||
if(list[i] == value) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Access an element by its position (0-based index)
|
||||
T access(int position){
|
||||
return list[position];
|
||||
}
|
||||
|
||||
// Return the current number of elements in the list
|
||||
int size(){
|
||||
return length;
|
||||
}
|
||||
|
||||
// Check if the list is empty
|
||||
bool isEmpty(){
|
||||
return length == 0;
|
||||
}
|
||||
|
||||
// Display the elements of the list
|
||||
void display(){
|
||||
for(int i=0;i<length;i++){
|
||||
cout<<list[i]<<" ";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
int main(){
|
||||
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
107
.config/Code/User/History/477921d5/vllg.cpp
Normal file
107
.config/Code/User/History/477921d5/vllg.cpp
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
#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){
|
||||
if(position > length) return;
|
||||
if(length >= capacity) resize();
|
||||
|
||||
for(int i=length;i>=position;i--){
|
||||
list[i+1] = list[i];
|
||||
}
|
||||
list[position] = value;
|
||||
length++;
|
||||
}
|
||||
|
||||
// Delete an element by its value (first occurrence)
|
||||
bool deleteByValue(T value){
|
||||
int index = search(value);
|
||||
deleteByPosition(index);
|
||||
}
|
||||
|
||||
// Delete an element by its position (0-based index)
|
||||
bool deleteByPosition(int position){
|
||||
if(position > length) return false;
|
||||
else{
|
||||
for(int i=position;i<length;i++){
|
||||
list[i] = list[i+1];
|
||||
}
|
||||
length--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Search for an element by its value, return the position if found, otherwise -1
|
||||
int search(T value){
|
||||
for(int i=0;i<length;i++){
|
||||
if(list[i] == value) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Access an element by its position (0-based index)
|
||||
T access(int position){
|
||||
return list[position];
|
||||
}
|
||||
|
||||
// Return the current number of elements in the list
|
||||
int size(){
|
||||
return length;
|
||||
}
|
||||
|
||||
// Check if the list is empty
|
||||
bool isEmpty(){
|
||||
return length == 0;
|
||||
}
|
||||
|
||||
// Display the elements of the list
|
||||
void display(){
|
||||
for(int i=0;i<length;i++){
|
||||
cout<<list[i]<<" ";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
int main(){
|
||||
|
||||
List<int> list;
|
||||
list.insert(0, 10);
|
||||
list.display();
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
98
.config/Code/User/History/477921d5/xrBq.cpp
Normal file
98
.config/Code/User/History/477921d5/xrBq.cpp
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
#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){
|
||||
if(length >= capacity) resize();
|
||||
|
||||
for(int i=length;i>=position;i--){
|
||||
list[i+1] = list[i];
|
||||
}
|
||||
list[position] = value;
|
||||
length++;
|
||||
}
|
||||
|
||||
// Delete an element by its value (first occurrence)
|
||||
bool deleteByValue(T value){
|
||||
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
104
.config/Code/User/History/477921d5/yD2s.cpp
Normal file
104
.config/Code/User/History/477921d5/yD2s.cpp
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
#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){
|
||||
if(length >= capacity) resize();
|
||||
|
||||
for(int i=length;i>=position;i--){
|
||||
list[i+1] = list[i];
|
||||
}
|
||||
list[position] = value;
|
||||
length++;
|
||||
}
|
||||
|
||||
// Delete an element by its value (first occurrence)
|
||||
bool deleteByValue(T value){
|
||||
int index = search(value);
|
||||
deleteByPosition(index);
|
||||
}
|
||||
|
||||
// Delete an element by its position (0-based index)
|
||||
bool deleteByPosition(int position){
|
||||
if(position > length) return false;
|
||||
else{
|
||||
for(int i=position;i<length;i++){
|
||||
list[i] = list[i+1];
|
||||
}
|
||||
length--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Search for an element by its value, return the position if found, otherwise -1
|
||||
int search(T value){
|
||||
for(int i=0;i<length;i++){
|
||||
if(list[i] == value) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Access an element by its position (0-based index)
|
||||
T access(int position){
|
||||
return list[position];
|
||||
}
|
||||
|
||||
// Return the current number of elements in the list
|
||||
int size(){
|
||||
return length;
|
||||
}
|
||||
|
||||
// Check if the list is empty
|
||||
bool isEmpty(){
|
||||
return length == 0;
|
||||
}
|
||||
|
||||
// Display the elements of the list
|
||||
void display(){
|
||||
for(int i=0;i<length;i++){
|
||||
cout<<list[i]<<" ";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
int main(){
|
||||
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
104
.config/Code/User/History/477921d5/zSCD.cpp
Normal file
104
.config/Code/User/History/477921d5/zSCD.cpp
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
#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){
|
||||
if(length >= capacity) resize();
|
||||
|
||||
for(int i=length;i>=position;i--){
|
||||
list[i+1] = list[i];
|
||||
}
|
||||
list[position] = value;
|
||||
length++;
|
||||
}
|
||||
|
||||
// Delete an element by its value (first occurrence)
|
||||
bool deleteByValue(T value){
|
||||
int index = search(value);
|
||||
deleteByPosition(index);
|
||||
}
|
||||
|
||||
// Delete an element by its position (0-based index)
|
||||
bool deleteByPosition(int position){
|
||||
if(position > length) return false;
|
||||
else{
|
||||
for(int i=position;i<length;i++){
|
||||
list[i] = list[i+1];
|
||||
}
|
||||
length--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Search for an element by its value, return the position if found, otherwise -1
|
||||
int search(T value){
|
||||
for(int i=0;i<length;i++){
|
||||
if(list[i] == value) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Access an element by its position (0-based index)
|
||||
T access(int position){
|
||||
return list[position];
|
||||
}
|
||||
|
||||
// Return the current number of elements in the list
|
||||
int size(){
|
||||
return length;
|
||||
}
|
||||
|
||||
// Check if the list is empty
|
||||
bool isEmpty(){
|
||||
return length == 0;
|
||||
}
|
||||
|
||||
// Display the elements of the list
|
||||
void display(){
|
||||
for(int i=0;i<length;i++){
|
||||
cout<<list[i]<<" ";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
int main(){
|
||||
|
||||
List<int> list;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue