This commit is contained in:
RafayAhmad7548 2024-09-09 16:59:28 +05:00
parent 2992f4f408
commit 4f46de8d00
3330 changed files with 394553 additions and 76939 deletions

View file

@ -0,0 +1,113 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(1), i(0), arr(new int[size]){}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
i++;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<i-1;j++){
arr[j] = arr[j+1];
}
i--;
if(i < size/4) decreaseCapacity();
}
return true;
}
bool updateElement(int index, int value){
if(index < 0 || index > size) return false;
arr[index] = value;
return true;
}
int get(int index) const{
if(index < 0 || index > size) return -1;
return arr[index];
}
int size() const{
return i;
}
int capacity() const{
return size;
}
void clear(){
delete arr;
arr = new int[1];
i = 0;
}
void reverse(){
int* newArr = new int[size];
for(int j=0;j<i;j++){
newArr[j] = arr[i-j-1];
}
delete arr;
newArr = arr;
}
int find(int value){
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,116 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(1), i(0), arr(new int[size]){}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
i++;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<i-1;j++){
arr[j] = arr[j+1];
}
i--;
if(i < size/4) decreaseCapacity();
}
return true;
}
bool updateElement(int index, int value){
if(index < 0 || index > size) return false;
arr[index] = value;
return true;
}
int get(int index) const{
if(index < 0 || index > size) return -1;
return arr[index];
}
int size() const{
return i;
}
int capacity() const{
return size;
}
void clear(){
delete arr;
arr = new int[1];
i = 0;
}
void reverse(){
int* newArr = new int[size];
for(int j=0;j<i;j++){
newArr[j] = arr[i-j-1];
}
delete arr;
newArr = arr;
}
int find(int value) const{
for(int j=0;j<i;j++){
if(arr[j] = value) return j;
}
return -1;
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,86 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(1), i(0), arr(new int[size]){}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<i;j++){
arr[j] = arr[j+1];
}
if(i < size/4) decreaseCapacity();
}
return true;
}
bool updateElement(int index, int value){
if(index < 0 || index > size) return false;
arr[index] = value;
return true;
}
int get(int index){
if(index < 0 || index > size) return -1;
return arr[index];
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,111 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(1), i(0), arr(new int[size]){}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
i++;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<i-1;j++){
arr[j] = arr[j+1];
}
i--;
if(i < size/4) decreaseCapacity();
}
return true;
}
bool updateElement(int index, int value){
if(index < 0 || index > size) return false;
arr[index] = value;
return true;
}
int get(int index) const{
if(index < 0 || index > size) return -1;
return arr[index];
}
int size() const{
return i;
}
int capacity() const{
return size;
}
void clear(){
delete arr;
arr = new int[1];
i = 0;
}
void reverse(){
int* newArr = new int[size];
for(int j=0;j<i;j++){
newArr[j] = arr[i-j-1];
}
delete arr;
newArr = arr;
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,71 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(1), i(0), arr(new int[size]){}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<i;j++){
arr[j] = arr[j+1];
}
}
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,132 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(10), i(0){
arr = new int[size];
}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
i++;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<i-1;j++){
arr[j] = arr[j+1];
}
i--;
if(i < size/4) decreaseCapacity();
}
return true;
}
bool updateElement(int index, int value){
if(index < 0 || index > size) return false;
arr[index] = value;
return true;
}
int get(int index) const{
if(index < 0 || index > size) return -1;
return arr[index];
}
int getSize() const{
return i;
}
int capacity() const{
return size;
}
void clear(){
delete arr;
arr = new int[1];
i = 0;
}
void reverse(){
int* newArr = new int[size];
for(int j=0;j<i;j++){
newArr[j] = arr[i-j-1];
}
delete arr;
newArr = arr;
}
int find(int value) const{
for(int j=0;j<i;j++){
if(arr[j] == value) return j;
}
return -1;
}
};
int main(){
ResizableArray arr;
arr.add(4);
arr.add(3);
arr.add(2);
arr.add(5);
arr.add(6);
arr.insert(2, 5);
arr.remove(2);
for(int i=0;i<arr.getSize();i++){
cout<<arr.get(i)<<endl;
}
return 0;
}

View file

@ -0,0 +1,77 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(1), i(0), arr(new int[size]){}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<i;j++){
arr[j] = arr[j+1];
}
if(i < size/4) decreaseCapacity();
}
return true;
}
bool updateElement(int index, int value){
if(index < 0 || index > size) return false;
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,131 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(10), i(0){
arr = new int[size];
}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
i++;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<i-1;j++){
arr[j] = arr[j+1];
}
i--;
if(i < size/4) decreaseCapacity();
}
return true;
}
bool updateElement(int index, int value){
if(index < 0 || index > size) return false;
arr[index] = value;
return true;
}
int get(int index) const{
if(index < 0 || index > size) return -1;
return arr[index];
}
int getSize() const{
return i;
}
int capacity() const{
return size;
}
void clear(){
delete arr;
arr = new int[1];
i = 0;
}
void reverse(){
int* newArr = new int[size];
for(int j=0;j<i;j++){
newArr[j] = arr[i-j-1];
}
delete arr;
newArr = arr;
}
int find(int value) const{
for(int j=0;j<i;j++){
if(arr[j] == value) return j;
}
return -1;
}
};
int main(){
ResizableArray arr;
arr.add(4);
arr.add(3);
arr.add(2);
arr.add(5);
arr.add(6);
for(int i=0;i<arr.getSize();i++){
cout<<arr.get(i)<<endl;
}
cout<<arr.find(3);
return 0;
}

View file

@ -0,0 +1,133 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(10), i(0){
arr = new int[size];
}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
i++;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<i-1;j++){
arr[j] = arr[j+1];
}
i--;
if(i < size/4) decreaseCapacity();
}
return true;
}
bool updateElement(int index, int value){
if(index < 0 || index > size) return false;
arr[index] = value;
return true;
}
int get(int index) const{
if(index < 0 || index > size) return -1;
return arr[index];
}
int getSize() const{
return i;
}
int capacity() const{
return size;
}
void clear(){
delete arr;
arr = new int[1];
i = 0;
}
void reverse(){
for(int j=0;j<i/2;j++){
int temp = arr[j];
arr[j] = arr[i-j-1];
arr[i-j] = temp;
}
}
int find(int value) const{
for(int j=0;j<i;j++){
if(arr[j] == value) return j;
}
return -1;
}
};
int main(){
ResizableArray arr;
arr.add(4);
arr.add(3);
arr.add(2);
arr.add(5);
arr.add(6);
for(int i=0;i<arr.getSize();i++){
cout<<arr.get(i)<<endl;
}
arr.reverse();
for(int i=0;i<arr.getSize();i++){
cout<<arr.get(i)<<endl;
}
return 0;
}

View file

@ -0,0 +1,77 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(1), i(0), arr(new int[size]){}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<i;j++){
arr[j] = arr[j+1];
}
if(i < size/4) decreaseCapacity();
}
return true;
}
void updateElement(int index, int value){
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,73 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(1), i(0), arr(new int[size]){}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<i;j++){
arr[j] = arr[j+1];
}
if(i < size/4) decreaseCapacity();
}
return true;
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,132 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(10), i(0){
arr = new int[size];
}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
i++;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<i-1;j++){
arr[j] = arr[j+1];
}
i--;
if(i < size/4) decreaseCapacity();
}
return true;
}
bool updateElement(int index, int value){
if(index < 0 || index > size) return false;
arr[index] = value;
return true;
}
int get(int index) const{
if(index < 0 || index > size) return -1;
return arr[index];
}
int getSize() const{
return i;
}
int capacity() const{
return size;
}
void clear(){
delete arr;
arr = new int[1];
i = 0;
}
void reverse(){
int* newArr = new int[size];
for(int j=0;j<i;j++){
newArr[j] = arr[i-j-1];
}
delete arr;
newArr = arr;
}
int find(int value) const{
for(int j=0;j<i;j++){
if(arr[j] = value)
return j;
}
return -1;
}
};
int main(){
ResizableArray arr;
arr.add(4);
arr.add(3);
arr.add(2);
arr.add(5);
arr.add(6);
for(int i=0;i<arr.getSize();i++){
cout<<arr.get(i)<<endl;
}
cout<<arr.find(3);
return 0;
}

View file

@ -0,0 +1,92 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(1), i(0), arr(new int[size]){}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
i++;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<i-1;j++){
arr[j] = arr[j+1];
}
i--;
if(i < size/4) decreaseCapacity();
}
return true;
}
bool updateElement(int index, int value){
if(index < 0 || index > size) return false;
arr[index] = value;
return true;
}
int get(int index) const{
if(index < 0 || index > size) return -1;
return arr[index];
}
int size() const{
return i;
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,96 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(1), i(0), arr(new int[size]){}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
i++;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<i-1;j++){
arr[j] = arr[j+1];
}
i--;
if(i < size/4) decreaseCapacity();
}
return true;
}
bool updateElement(int index, int value){
if(index < 0 || index > size) return false;
arr[index] = value;
return true;
}
int get(int index) const{
if(index < 0 || index > size) return -1;
return arr[index];
}
int size() const{
return i;
}
int capacity() const{
return size;
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,131 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(10), i(0){
arr = new int[size];
}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
i++;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<i-1;j++){
arr[j] = arr[j+1];
}
i--;
if(i < size/4) decreaseCapacity();
}
return true;
}
bool updateElement(int index, int value){
if(index < 0 || index > size) return false;
arr[index] = value;
return true;
}
int get(int index) const{
if(index < 0 || index > size) return -1;
return arr[index];
}
int getSize() const{
return i;
}
int capacity() const{
return size;
}
void clear(){
delete arr;
arr = new int[1];
i = 0;
}
void reverse(){
int* newArr = new int[size];
for(int j=0;j<i;j++){
newArr[j] = arr[i-j-1];
}
delete arr;
newArr = arr;
}
int find(int value) const{
for(int j=0;j<i;j++){
if(arr[j] = value) return j;
}
return -1;
}
};
int main(){
ResizableArray arr;
arr.add(4);
arr.add(3);
arr.add(2);
arr.add(5);
arr.add(6);
for(int i=0;i<arr.getSize();i++){
cout<<arr.get(i)<<endl;
}
cout<<arr.find(3);
return 0;
}

View file

@ -0,0 +1,71 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(1), i(0), arr(new int[size]){}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<i;j++){
arr[j] = arr[j+1];
}
}
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,134 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(10), i(0){
arr = new int[size];
}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
i++;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<i-1;j++){
arr[j] = arr[j+1];
}
i--;
if(i < size/4) decreaseCapacity();
}
return true;
}
bool updateElement(int index, int value){
if(index < 0 || index > size) return false;
arr[index] = value;
return true;
}
int get(int index) const{
if(index < 0 || index > size) return -1;
return arr[index];
}
int getSize() const{
return i;
}
int capacity() const{
return size;
}
void clear(){
delete arr;
arr = new int[1];
i = 0;
}
void reverse(){
for(int j=0;j<i/2;j++){
int temp = arr[j];
arr[j] = arr[i-j-1];
arr[i-j] = temp;
}
}
int find(int value) const{
for(int j=0;j<i;j++){
if(arr[j] == value) return j;
}
return -1;
}
};
int main(){
ResizableArray arr;
arr.add(4);
arr.add(3);
arr.add(2);
arr.add(5);
arr.add(6);
for(int i=0;i<arr.getSize();i++){
cout<<arr.get(i)<<endl;
}
arr.reverse();
for(int i=0;i<arr.getSize();i++){
cout<<arr.get(i)<<endl;
}
return 0;
}

View file

@ -0,0 +1,116 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(1), i(0), arr(new int[size]){}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
i++;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<i-1;j++){
arr[j] = arr[j+1];
}
i--;
if(i < size/4) decreaseCapacity();
}
return true;
}
bool updateElement(int index, int value){
if(index < 0 || index > size) return false;
arr[index] = value;
return true;
}
int get(int index) const{
if(index < 0 || index > size) return -1;
return arr[index];
}
int getSize() const{
return i;
}
int capacity() const{
return size;
}
void clear(){
delete arr;
arr = new int[1];
i = 0;
}
void reverse(){
int* newArr = new int[size];
for(int j=0;j<i;j++){
newArr[j] = arr[i-j-1];
}
delete arr;
newArr = arr;
}
int find(int value) const{
for(int j=0;j<i;j++){
if(arr[j] = value) return j;
}
return -1;
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,133 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(10), i(0){
arr = new int[size];
}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
i++;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<i-1;j++){
arr[j] = arr[j+1];
}
i--;
if(i < size/4) decreaseCapacity();
}
return true;
}
bool updateElement(int index, int value){
if(index < 0 || index > size) return false;
arr[index] = value;
return true;
}
int get(int index) const{
if(index < 0 || index > size) return -1;
return arr[index];
}
int getSize() const{
return i;
}
int capacity() const{
return size;
}
void clear(){
delete arr;
arr = new int[1];
i = 0;
}
void reverse(){
int* newArr = new int[size];
for(int j=0;j<i;j++){
newArr[j] = arr[i-j-1];
}
delete arr;
newArr = arr;
}
int find(int value) const{
for(int j=0;j<i;j++){
if(arr[j] == value) return j;
}
return -1;
}
};
int main(){
ResizableArray arr;
arr.add(4);
arr.add(3);
arr.add(2);
arr.add(5);
arr.add(6);
arr.remove(4);
arr.updateElement(3, 10);
arr.clear();
for(int i=0;i<arr.getSize();i++){
cout<<arr.get(i)<<endl;
}
return 0;
}

View file

@ -0,0 +1,79 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(1), i(0), arr(new int[size]){}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<i;j++){
arr[j] = arr[j+1];
}
if(i < size/4) decreaseCapacity();
}
return true;
}
bool updateElement(int index, int value){
if(index < 0 || index > size) return false;
arr[index] = value;
return true;
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,92 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(1), i(0), arr(new int[size]){}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
i++;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<i;j++){
arr[j] = arr[j+1];
}
i--;
if(i < size/4) decreaseCapacity();
}
return true;
}
bool updateElement(int index, int value){
if(index < 0 || index > size) return false;
arr[index] = value;
return true;
}
int get(int index) const{
if(index < 0 || index > size) return -1;
return arr[index];
}
int size() const{
return i+1;
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,72 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(1), i(0), arr(new int[size]){}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<i;j++){
arr[j] = arr[j+1];
}
if(i < size/4) decreaseCapacity();
}
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,135 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(10), i(0){
arr = new int[size];
}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
i++;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<i-1;j++){
arr[j] = arr[j+1];
}
i--;
if(i < size/4) decreaseCapacity();
}
return true;
}
bool updateElement(int index, int value){
if(index < 0 || index > size) return false;
arr[index] = value;
return true;
}
int get(int index) const{
if(index < 0 || index > size) return -1;
return arr[index];
}
int getSize() const{
return i;
}
int capacity() const{
return size;
}
void clear(){
delete arr;
arr = new int[1];
i = 0;
}
void reverse(){
for(int j=0;j<i/2;j++){
int temp = arr[j];
arr[j] = arr[i-j];
arr[i-j] = temp;
}
}
int find(int value) const{
for(int j=0;j<i;j++){
if(arr[j] == value) return j;
}
return -1;
}
};
int main(){
ResizableArray arr;
arr.add(4);
arr.add(3);
arr.add(2);
arr.add(5);
arr.add(6);
arr.remove(4);
arr.updateElement(3, 10);
for(int i=0;i<arr.getSize();i++){
cout<<arr.get(i)<<endl;
}
arr.reverse();
for(int i=0;i<arr.getSize();i++){
cout<<arr.get(i)<<endl;
}
return 0;
}

View file

@ -0,0 +1,133 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(10), i(0){
arr = new int[size];
}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
i++;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<i-1;j++){
arr[j] = arr[j+1];
}
i--;
if(i < size/4) decreaseCapacity();
}
return true;
}
bool updateElement(int index, int value){
if(index < 0 || index > size) return false;
arr[index] = value;
return true;
}
int get(int index) const{
if(index < 0 || index > size) return -1;
return arr[index];
}
int getSize() const{
return i;
}
int capacity() const{
return size;
}
void clear(){
delete arr;
arr = new int[1];
i = 0;
}
void reverse(){
int* newArr = new int[size];
for(int j=0;j<i;j++){
newArr[j] = arr[i-j-1];
}
delete arr;
newArr = arr;
}
int find(int value) const{
for(int j=0;j<i;j++){
if(arr[j] == value) return j;
}
return -1;
}
};
int main(){
ResizableArray arr;
arr.add(4);
arr.add(3);
arr.add(2);
arr.add(5);
arr.add(6);
arr.remove(4);
arr.updateElement(3, 10);
arr.reverse();
for(int i=0;i<arr.getSize();i++){
cout<<arr.get(i)<<endl;
}
return 0;
}

View file

@ -0,0 +1,132 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(10), i(0){
arr = new int[size];
}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
i++;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<i-1;j++){
arr[j] = arr[j+1];
}
i--;
if(i < size/4) decreaseCapacity();
}
return true;
}
bool updateElement(int index, int value){
if(index < 0 || index > size) return false;
arr[index] = value;
return true;
}
int get(int index) const{
if(index < 0 || index > size) return -1;
return arr[index];
}
int getSize() const{
return i;
}
int capacity() const{
return size;
}
void clear(){
delete arr;
arr = new int[1];
i = 0;
}
void reverse(){
int* newArr = new int[size];
for(int j=0;j<i;j++){
newArr[j] = arr[i-j-1];
}
delete arr;
newArr = arr;
}
int find(int value) const{
for(int j=0;j<i;j++){
if(arr[j] == value) return j;
}
return -1;
}
};
int main(){
ResizableArray arr;
arr.add(4);
arr.add(3);
arr.add(2);
arr.add(5);
arr.add(6);
arr.insert(2, 5);
arr.remove(4);
for(int i=0;i<arr.getSize();i++){
cout<<arr.get(i)<<endl;
}
return 0;
}

View file

@ -0,0 +1,136 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete[] arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete[] arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(10), i(0){
arr = new int[size];
}
~ResizableArray(){
delete[] arr;
}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
i++;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<i-1;j++){
arr[j] = arr[j+1];
}
i--;
if(i < size/4) decreaseCapacity();
}
return true;
}
bool updateElement(int index, int value){
if(index < 0 || index > size) return false;
arr[index] = value;
return true;
}
int get(int index) const{
if(index < 0 || index > size) return -1;
return arr[index];
}
int getSize() const{
return i;
}
int capacity() const{
return size;
}
void clear(){
delete[] arr;
arr = new int[1];
i = 0;
}
void reverse(){
for(int j=0;j<i/2;j++){
int temp = arr[j];
arr[j] = arr[i-j-1];
arr[i-j] = temp;
}
}
int find(int value) const{
for(int j=0;j<i;j++){
if(arr[j] == value) return j;
}
return -1;
}
};
int main(){
ResizableArray arr;
arr.add(4);
arr.add(3);
arr.add(2);
arr.add(5);
arr.add(6);
for(int i=0;i<arr.getSize();i++){
cout<<arr.get(i)<<endl;
}
arr.reverse();
for(int i=0;i<arr.getSize();i++){
cout<<arr.get(i)<<endl;
}
return 0;
}

View file

@ -0,0 +1,127 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(10), i(0), arr(new int[size]){}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
i++;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<i-1;j++){
arr[j] = arr[j+1];
}
i--;
if(i < size/4) decreaseCapacity();
}
return true;
}
bool updateElement(int index, int value){
if(index < 0 || index > size) return false;
arr[index] = value;
return true;
}
int get(int index) const{
if(index < 0 || index > size) return -1;
return arr[index];
}
int getSize() const{
return i;
}
int capacity() const{
return size;
}
void clear(){
delete arr;
arr = new int[1];
i = 0;
}
void reverse(){
int* newArr = new int[size];
for(int j=0;j<i;j++){
newArr[j] = arr[i-j-1];
}
delete arr;
newArr = arr;
}
int find(int value) const{
for(int j=0;j<i;j++){
if(arr[j] = value) return j;
}
return -1;
}
};
int main(){
ResizableArray arr;
arr.add(4);
arr.add(3);
arr.add(2);
arr.add(5);
arr.add(6);
for(int i=0;i<arr.getSize();i++){
arr.get(i);
}
return 0;
}

View file

@ -0,0 +1,92 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(1), i(0), arr(new int[size]){}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
i++;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<=i;j++){
arr[j] = arr[j+1];
}
i--;
if(i < size/4) decreaseCapacity();
}
return true;
}
bool updateElement(int index, int value){
if(index < 0 || index > size) return false;
arr[index] = value;
return true;
}
int get(int index) const{
if(index < 0 || index > size) return -1;
return arr[index];
}
int size() const{
return i;
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,129 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(10), i(0){
arr = new int[size];
}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
i++;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<i-1;j++){
arr[j] = arr[j+1];
}
i--;
if(i < size/4) decreaseCapacity();
}
return true;
}
bool updateElement(int index, int value){
if(index < 0 || index > size) return false;
arr[index] = value;
return true;
}
int get(int index) const{
if(index < 0 || index > size) return -1;
return arr[index];
}
int getSize() const{
return i;
}
int capacity() const{
return size;
}
void clear(){
delete arr;
arr = new int[1];
i = 0;
}
void reverse(){
int* newArr = new int[size];
for(int j=0;j<i;j++){
newArr[j] = arr[i-j-1];
}
delete arr;
newArr = arr;
}
int find(int value) const{
for(int j=0;j<i;j++){
if(arr[j] = value) return j;
}
return -1;
}
};
int main(){
ResizableArray arr;
arr.add(4);
arr.add(3);
arr.add(2);
arr.add(5);
arr.add(6);
for(int i=0;i<arr.getSize();i++){
cout<<arr.get(i)<<endl;
}
return 0;
}

View file

@ -0,0 +1,133 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(10), i(0){
arr = new int[size];
}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
i++;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<i-1;j++){
arr[j] = arr[j+1];
}
i--;
if(i < size/4) decreaseCapacity();
}
return true;
}
bool updateElement(int index, int value){
if(index < 0 || index > size) return false;
arr[index] = value;
return true;
}
int get(int index) const{
if(index < 0 || index > size) return -1;
return arr[index];
}
int getSize() const{
return i;
}
int capacity() const{
return size;
}
void clear(){
delete arr;
arr = new int[1];
i = 0;
}
void reverse(){
for(int j=0;j<i/2;j++){
int temp = arr[j];
arr[j] = arr[i-j];
arr[i-j] = temp;
}
}
int find(int value) const{
for(int j=0;j<i;j++){
if(arr[j] == value) return j;
}
return -1;
}
};
int main(){
ResizableArray arr;
arr.add(4);
arr.add(3);
arr.add(2);
arr.add(5);
arr.add(6);
for(int i=0;i<arr.getSize();i++){
cout<<arr.get(i)<<endl;
}
arr.reverse();
for(int i=0;i<arr.getSize();i++){
cout<<arr.get(i)<<endl;
}
return 0;
}

View file

@ -0,0 +1,133 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(10), i(0){
arr = new int[size];
}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
i++;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<i-1;j++){
arr[j] = arr[j+1];
}
i--;
if(i < size/4) decreaseCapacity();
}
return true;
}
bool updateElement(int index, int value){
if(index < 0 || index > size) return false;
arr[index] = value;
return true;
}
int get(int index) const{
if(index < 0 || index > size) return -1;
return arr[index];
}
int getSize() const{
return i;
}
int capacity() const{
return size;
}
void clear(){
delete arr;
arr = new int[1];
i = 0;
}
void reverse(){
for(int j=0;j<=i/2;j++){
int temp = arr[j];
arr[j] = arr[i-j];
arr[i-j] = temp;
}
}
int find(int value) const{
for(int j=0;j<i;j++){
if(arr[j] == value) return j;
}
return -1;
}
};
int main(){
ResizableArray arr;
arr.add(4);
arr.add(3);
arr.add(2);
arr.add(5);
arr.add(6);
for(int i=0;i<arr.getSize();i++){
cout<<arr.get(i)<<endl;
}
arr.reverse();
for(int i=0;i<arr.getSize();i++){
cout<<arr.get(i)<<endl;
}
return 0;
}

View file

@ -0,0 +1,131 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(10), i(0){
arr = new int[size];
}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
i++;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<i-1;j++){
arr[j] = arr[j+1];
}
i--;
if(i < size/4) decreaseCapacity();
}
return true;
}
bool updateElement(int index, int value){
if(index < 0 || index > size) return false;
arr[index] = value;
return true;
}
int get(int index) const{
if(index < 0 || index > size) return -1;
return arr[index];
}
int getSize() const{
return i;
}
int capacity() const{
return size;
}
void clear(){
delete arr;
arr = new int[1];
i = 0;
}
void reverse(){
int* newArr = new int[size];
for(int j=0;j<i;j++){
newArr[j] = arr[i-j-1];
}
delete arr;
newArr = arr;
}
int find(int value) const{
for(int j=0;j<i;j++){
if(arr[j] == value) return j;
}
return -1;
}
};
int main(){
ResizableArray arr;
arr.add(4);
arr.add(3);
arr.add(2);
arr.add(5);
arr.add(6);
arr.remove(4);
for(int i=0;i<arr.getSize();i++){
cout<<arr.get(i)<<endl;
}
return 0;
}

View file

@ -0,0 +1,92 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(1), i(0), arr(new int[size]){}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
i++;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<i;j++){
arr[j] = arr[j+1];
}
i--;
if(i < size/4) decreaseCapacity();
}
return true;
}
bool updateElement(int index, int value){
if(index < 0 || index > size) return false;
arr[index] = value;
return true;
}
int get(int index) const{
if(index < 0 || index > size) return -1;
return arr[index];
}
int size() const{
return i;
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,90 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(1), i(0), arr(new int[size]){}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<i;j++){
arr[j] = arr[j+1];
}
if(i < size/4) decreaseCapacity();
}
return true;
}
bool updateElement(int index, int value){
if(index < 0 || index > size) return false;
arr[index] = value;
return true;
}
int get(int index) const{
if(index < 0 || index > size) return -1;
return arr[index];
}
int size() const{
return i+1;
}
};
int main(){
return 0;
}

View file

@ -0,0 +1 @@
{"version":1,"resource":"file:///home/rafayahmad/Stuff/Coding/C%2B%2B/DS/lab2/task2.cpp","entries":[{"id":"IYSV.cpp","timestamp":1725273478026},{"id":"2eaO.cpp","timestamp":1725273490469},{"id":"OQgS.cpp","timestamp":1725273524006},{"id":"Byp6.cpp","timestamp":1725273535583},{"id":"Acme.cpp","timestamp":1725273591580},{"id":"7IEa.cpp","timestamp":1725273636227},{"id":"MH8H.cpp","timestamp":1725273651617},{"id":"259Z.cpp","timestamp":1725273680774},{"id":"ewtW.cpp","timestamp":1725273699700},{"id":"d6pt.cpp","timestamp":1725273712174},{"id":"MNDW.cpp","timestamp":1725273729794},{"id":"cyJI.cpp","timestamp":1725273783078},{"id":"VNZi.cpp","timestamp":1725273799321},{"id":"u4My.cpp","timestamp":1725273812281},{"id":"CZEH.cpp","timestamp":1725273928815},{"id":"EhP4.cpp","timestamp":1725273941692},{"id":"goHP.cpp","timestamp":1725273986756},{"id":"2H9c.cpp","timestamp":1725274092773},{"id":"vMGW.cpp","timestamp":1725274112777},{"id":"0273.cpp","timestamp":1725274136717},{"id":"sitg.cpp","timestamp":1725274190627},{"id":"pL11.cpp","timestamp":1725274276648},{"id":"0UIr.cpp","timestamp":1725274330342},{"id":"KkMQ.cpp","timestamp":1725275956793},{"id":"rOgn.cpp","timestamp":1725276472744},{"id":"uI1Q.cpp","timestamp":1725276497413},{"id":"V3zR.cpp","timestamp":1725276527995},{"id":"guY1.cpp","timestamp":1725276669761},{"id":"vxab.cpp","timestamp":1725276700620},{"id":"mld0.cpp","timestamp":1725276727036},{"id":"Zdr7.cpp","timestamp":1725276800254},{"id":"IQdm.cpp","timestamp":1725276815531},{"id":"CQdO.cpp","timestamp":1725276882643},{"id":"8Twa.cpp","timestamp":1725276918572},{"id":"jRaE.cpp","timestamp":1725276952478},{"id":"p5Gz.cpp","timestamp":1725276977584},{"id":"6zST.cpp","timestamp":1725276999031},{"id":"SrE1.cpp","timestamp":1725277009944},{"id":"cPvv.cpp","timestamp":1725277032277},{"id":"LJcN.cpp","timestamp":1725277060643},{"id":"Qzc1.cpp","timestamp":1725277073379},{"id":"iBTl.cpp","timestamp":1725277102496},{"id":"v6GZ.cpp","timestamp":1725277169831},{"id":"PNol.cpp","timestamp":1725277186301},{"id":"yueQ.cpp","timestamp":1725277200434},{"id":"c9bR.cpp","timestamp":1725277215824},{"id":"ain2.cpp","timestamp":1725277234481},{"id":"8ZkC.cpp","timestamp":1725277256284},{"id":"KHkg.cpp","timestamp":1725277496542},{"id":"UOso.cpp","timestamp":1725277526358}]}

View file

@ -0,0 +1,86 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(1), i(0), arr(new int[size]){}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<i;j++){
arr[j] = arr[j+1];
}
if(i < size/4) decreaseCapacity();
}
return true;
}
bool updateElement(int index, int value){
if(index < 0 || index > size) return false;
arr[index] = value;
return true;
}
int get(int index) const{
if(index < 0 || index > size) return -1;
return arr[index];
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,100 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(1), i(0), arr(new int[size]){}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
i++;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<i-1;j++){
arr[j] = arr[j+1];
}
i--;
if(i < size/4) decreaseCapacity();
}
return true;
}
bool updateElement(int index, int value){
if(index < 0 || index > size) return false;
arr[index] = value;
return true;
}
int get(int index) const{
if(index < 0 || index > size) return -1;
return arr[index];
}
int size() const{
return i;
}
int capacity() const{
return size;
}
void clear() const{
delete arr;
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,129 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(10), i(0){
arr = new int[size];
}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
i++;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<i-1;j++){
arr[j] = arr[j+1];
}
i--;
if(i < size/4) decreaseCapacity();
}
return true;
}
bool updateElement(int index, int value){
if(index < 0 || index > size) return false;
arr[index] = value;
return true;
}
int get(int index) const{
if(index < 0 || index > size) return -1;
return arr[index];
}
int getSize() const{
return i;
}
int capacity() const{
return size;
}
void clear(){
delete arr;
arr = new int[1];
i = 0;
}
void reverse(){
int* newArr = new int[size];
for(int j=0;j<i;j++){
newArr[j] = arr[i-j-1];
}
delete arr;
newArr = arr;
}
int find(int value) const{
for(int j=0;j<i;j++){
if(arr[j] = value) return j;
}
return -1;
}
};
int main(){
ResizableArray arr;
arr.add(4);
arr.add(3);
arr.add(2);
arr.add(5);
arr.add(6);
for(int i=0;i<arr.getSize();i++){
arr.get(i);
}
return 0;
}

View file

@ -0,0 +1,128 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(10), i(0){
arr = new int[size];
}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
i++;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<i-1;j++){
arr[j] = arr[j+1];
}
i--;
if(i < size/4) decreaseCapacity();
}
return true;
}
bool updateElement(int index, int value){
if(index < 0 || index > size) return false;
arr[index] = value;
return true;
}
int get(int index) const{
if(index < 0 || index > size) return -1;
return arr[index];
}
int getSize() const{
return i;
}
int capacity() const{
return size;
}
void clear(){
delete arr;
arr = new int[1];
i = 0;
}
void reverse(){
}
int find(int value) const{
for(int j=0;j<i;j++){
if(arr[j] == value) return j;
}
return -1;
}
};
int main(){
ResizableArray arr;
arr.add(4);
arr.add(3);
arr.add(2);
arr.add(5);
arr.add(6);
arr.remove(4);
arr.updateElement(3, 10);
arr.reverse();
for(int i=0;i<arr.getSize();i++){
cout<<arr.get(i)<<endl;
}
return 0;
}

View file

@ -0,0 +1,131 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(10), i(0){
arr = new int[size];
}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
i++;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<i-1;j++){
arr[j] = arr[j+1];
}
i--;
if(i < size/4) decreaseCapacity();
}
return true;
}
bool updateElement(int index, int value){
if(index < 0 || index > size) return false;
arr[index] = value;
return true;
}
int get(int index) const{
if(index < 0 || index > size) return -1;
return arr[index];
}
int getSize() const{
return i;
}
int capacity() const{
return size;
}
void clear(){
delete arr;
arr = new int[1];
i = 0;
}
void reverse(){
int* newArr = new int[size];
for(int j=0;j<i;j++){
newArr[j] = arr[i-j-1];
}
delete arr;
newArr = arr;
}
int find(int value) const{
for(int j=0;j<i;j++){
if(arr[j] == value) return j;
}
return -1;
}
};
int main(){
ResizableArray arr;
arr.add(4);
arr.add(3);
arr.add(2);
arr.add(5);
arr.add(6);
cout<<arr.insert(2, 5);
for(int i=0;i<arr.getSize();i++){
cout<<arr.get(i)<<endl;
}
return 0;
}

View file

@ -0,0 +1,127 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(10), i(0), arr(new int[size]){}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
i++;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<i-1;j++){
arr[j] = arr[j+1];
}
i--;
if(i < size/4) decreaseCapacity();
}
return true;
}
bool updateElement(int index, int value){
if(index < 0 || index > size) return false;
arr[index] = value;
return true;
}
int get(int index) const{
if(index < 0 || index > size) return -1;
return arr[index];
}
int getSize() const{
return i;
}
int capacity() const{
return size;
}
void clear(){
delete arr;
arr = new int[1];
i = 0;
}
void reverse(){
int* newArr = new int[size];
for(int j=0;j<i;j++){
newArr[j] = arr[i-j-1];
}
delete arr;
newArr = arr;
}
int find(int value) const{
for(int j=0;j<i;j++){
if(arr[j] = value) return j;
}
return -1;
}
};
int main(){
ResizableArray arr;
arr.add(4);
arr.add(3);
arr.add(2);
arr.add(5);
arr.add(6);
for(int i=0;i<arr.getSize();i++){
cout<<arr.get(i)<<endl;
}
return 0;
}

View file

@ -0,0 +1,131 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(10), i(0){
arr = new int[size];
}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
i++;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<i-1;j++){
arr[j] = arr[j+1];
}
i--;
if(i < size/4) decreaseCapacity();
}
return true;
}
bool updateElement(int index, int value){
if(index < 0 || index > size) return false;
arr[index] = value;
return true;
}
int get(int index) const{
if(index < 0 || index > size) return -1;
return arr[index];
}
int getSize() const{
return i;
}
int capacity() const{
return size;
}
void clear(){
delete arr;
arr = new int[1];
i = 0;
}
void reverse(){
int* newArr = new int[size];
for(int j=0;j<i;j++){
newArr[j] = arr[i-j-1];
}
delete arr;
newArr = arr;
}
int find(int value) const{
for(int j=0;j<i;j++){
if(arr[j] == value) return j;
}
return -1;
}
};
int main(){
ResizableArray arr;
arr.add(4);
arr.add(3);
arr.add(2);
arr.add(5);
arr.add(6);
arr.insert(2, 5);
for(int i=0;i<arr.getSize();i++){
cout<<arr.get(i)<<endl;
}
return 0;
}

View file

@ -0,0 +1,115 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(1), i(0), arr(new int[size]){}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
i++;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<i-1;j++){
arr[j] = arr[j+1];
}
i--;
if(i < size/4) decreaseCapacity();
}
return true;
}
bool updateElement(int index, int value){
if(index < 0 || index > size) return false;
arr[index] = value;
return true;
}
int get(int index) const{
if(index < 0 || index > size) return -1;
return arr[index];
}
int size() const{
return i;
}
int capacity() const{
return size;
}
void clear(){
delete arr;
arr = new int[1];
i = 0;
}
void reverse(){
int* newArr = new int[size];
for(int j=0;j<i;j++){
newArr[j] = arr[i-j-1];
}
delete arr;
newArr = arr;
}
int find(int value) const{
for(int j=0;j<i;j++){
}
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,124 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(1), i(0), arr(new int[size]){}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
i++;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<i-1;j++){
arr[j] = arr[j+1];
}
i--;
if(i < size/4) decreaseCapacity();
}
return true;
}
bool updateElement(int index, int value){
if(index < 0 || index > size) return false;
arr[index] = value;
return true;
}
int get(int index) const{
if(index < 0 || index > size) return -1;
return arr[index];
}
int getSize() const{
return i;
}
int capacity() const{
return size;
}
void clear(){
delete arr;
arr = new int[1];
i = 0;
}
void reverse(){
int* newArr = new int[size];
for(int j=0;j<i;j++){
newArr[j] = arr[i-j-1];
}
delete arr;
newArr = arr;
}
int find(int value) const{
for(int j=0;j<i;j++){
if(arr[j] = value) return j;
}
return -1;
}
};
int main(){
ResizableArray arr;
arr.add(4);
arr.add(3);
arr.add(2);
arr.add(5);
arr.add(6);
return 0;
}

View file

@ -0,0 +1,113 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(1), i(0), arr(new int[size]){}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
i++;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<i-1;j++){
arr[j] = arr[j+1];
}
i--;
if(i < size/4) decreaseCapacity();
}
return true;
}
bool updateElement(int index, int value){
if(index < 0 || index > size) return false;
arr[index] = value;
return true;
}
int get(int index) const{
if(index < 0 || index > size) return -1;
return arr[index];
}
int size() const{
return i;
}
int capacity() const{
return size;
}
void clear(){
delete arr;
arr = new int[1];
i = 0;
}
void reverse(){
int* newArr = new int[size];
for(int j=0;j<i;j++){
newArr[j] = arr[i-j-1];
}
delete arr;
newArr = arr;
}
int find(int value) const{
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,92 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(1), i(0), arr(new int[size]){}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
i++;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<i;j++){
arr[j] = arr[j+1];
}
i--;
if(i < size/4) decreaseCapacity();
}
return true;
}
bool updateElement(int index, int value){
if(index < 0 || index > size) return false;
arr[index] = value;
return true;
}
int get(int index) const{
if(index < 0 || index > size) return -1;
return arr[index];
}
int size() const{
return i;
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,127 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(1), i(0), arr(new int[size]){}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
i++;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<i-1;j++){
arr[j] = arr[j+1];
}
i--;
if(i < size/4) decreaseCapacity();
}
return true;
}
bool updateElement(int index, int value){
if(index < 0 || index > size) return false;
arr[index] = value;
return true;
}
int get(int index) const{
if(index < 0 || index > size) return -1;
return arr[index];
}
int getSize() const{
return i;
}
int capacity() const{
return size;
}
void clear(){
delete arr;
arr = new int[1];
i = 0;
}
void reverse(){
int* newArr = new int[size];
for(int j=0;j<i;j++){
newArr[j] = arr[i-j-1];
}
delete arr;
newArr = arr;
}
int find(int value) const{
for(int j=0;j<i;j++){
if(arr[j] = value) return j;
}
return -1;
}
};
int main(){
ResizableArray arr;
arr.add(4);
arr.add(3);
arr.add(2);
arr.add(5);
arr.add(6);
for(int i=0;i<arr.getSize();i++){
arr.get(i);
}
return 0;
}

View file

@ -0,0 +1,132 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(10), i(0){
arr = new int[size];
}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
i++;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<i-1;j++){
arr[j] = arr[j+1];
}
i--;
if(i < size/4) decreaseCapacity();
}
return true;
}
bool updateElement(int index, int value){
if(index < 0 || index > size) return false;
arr[index] = value;
return true;
}
int get(int index) const{
if(index < 0 || index > size) return -1;
return arr[index];
}
int getSize() const{
return i;
}
int capacity() const{
return size;
}
void clear(){
delete arr;
arr = new int[1];
i = 0;
}
void reverse(){
for(int j=0;j<i/2;j++){
int temp = arr[j];
arr[j] = arr[i-j];
arr[i-j] = temp;
}
}
int find(int value) const{
for(int j=0;j<i;j++){
if(arr[j] == value) return j;
}
return -1;
}
};
int main(){
ResizableArray arr;
arr.add(4);
arr.add(3);
arr.add(2);
arr.add(5);
arr.add(6);
arr.remove(4);
arr.updateElement(3, 10);
arr.reverse();
for(int i=0;i<arr.getSize();i++){
cout<<arr.get(i)<<endl;
}
return 0;
}

View file

@ -0,0 +1,115 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(1), i(0), arr(new int[size]){}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
i++;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<i-1;j++){
arr[j] = arr[j+1];
}
i--;
if(i < size/4) decreaseCapacity();
}
return true;
}
bool updateElement(int index, int value){
if(index < 0 || index > size) return false;
arr[index] = value;
return true;
}
int get(int index) const{
if(index < 0 || index > size) return -1;
return arr[index];
}
int size() const{
return i;
}
int capacity() const{
return size;
}
void clear(){
delete arr;
arr = new int[1];
i = 0;
}
void reverse(){
int* newArr = new int[size];
for(int j=0;j<i;j++){
newArr[j] = arr[i-j-1];
}
delete arr;
newArr = arr;
}
int find(int value){
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,129 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(10), i(0){
arr = new int[size];
}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
i++;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<i-1;j++){
arr[j] = arr[j+1];
}
i--;
if(i < size/4) decreaseCapacity();
}
return true;
}
bool updateElement(int index, int value){
if(index < 0 || index > size) return false;
arr[index] = value;
return true;
}
int get(int index) const{
if(index < 0 || index > size) return -1;
return arr[index];
}
int getSize() const{
return i;
}
int capacity() const{
return size;
}
void clear(){
delete arr;
arr = new int[1];
i = 0;
}
void reverse(){
int* newArr = new int[size];
for(int j=0;j<i;j++){
newArr[j] = arr[i-j-1];
}
delete arr;
newArr = arr;
}
int find(int value) const{
for(int j=0;j<i;j++){
if(arr[j] = value) return j;
}
return -1;
}
};
int main(){
ResizableArray arr;
arr.add(4);
arr.add(3);
arr.add(2);
arr.add(5);
arr.add(6);
for(int i=0;i<arr.getSize();i++){
cout<<arr.get(i)<<endl;
}
return 0;
}

View file

@ -0,0 +1,133 @@
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class ResizableArray{
int* arr;
int size;
int i;
void increaseCapacity(){
int* newArr = new int[size*2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size *= 2;
}
void decreaseCapacity(){
int* newArr = new int[size/2];
for(int j=0;j<size;j++){
newArr[j] = arr[j];
}
delete arr;
arr = newArr;
size /= 2;
}
public:
ResizableArray() : size(10), i(0){
arr = new int[size];
}
void add(int value){
if(i >= size) increaseCapacity();
arr[i] = value;
i++;
}
bool insert(int index, int value){
if(index < 0 || index > size) return false;
else{
if(i >= size) increaseCapacity();
for(int j=i;j>=index;j--){
arr[j+1] = arr[j];
}
arr[index] = value;
i++;
}
return true;
}
bool remove(int index){
if(index < 0 || index > size) return false;
else{
for(int j=index;j<i-1;j++){
arr[j] = arr[j+1];
}
i--;
if(i < size/4) decreaseCapacity();
}
return true;
}
bool updateElement(int index, int value){
if(index < 0 || index > size) return false;
arr[index] = value;
return true;
}
int get(int index) const{
if(index < 0 || index > size) return -1;
return arr[index];
}
int getSize() const{
return i;
}
int capacity() const{
return size;
}
void clear(){
delete arr;
arr = new int[1];
i = 0;
}
void reverse(){
for(int j=0;j<i/2;j++){
int temp = arr[j];
arr[j] = arr[i-j];
arr[i-j] = temp;
}
}
int find(int value) const{
for(int j=0;j<i;j++){
if(arr[j] == value) return j;
}
return -1;
}
};
int main(){
ResizableArray arr;
arr.add(4);
arr.add(3);
arr.add(2);
arr.add(5);
arr.add(6);
for(int i=0;i<arr.getSize();i++){
cout<<arr.get(i)<<endl;
}
arr.reverse();
for(int i=0;i<arr.getSize();i++){
cout<<arr.get(i)<<endl;
}
return 0;
}