update
This commit is contained in:
parent
2992f4f408
commit
4f46de8d00
3330 changed files with 394553 additions and 76939 deletions
113
.config/Code/User/History/5797a381/0273.cpp
Normal file
113
.config/Code/User/History/5797a381/0273.cpp
Normal 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;
|
||||
}
|
116
.config/Code/User/History/5797a381/0UIr.cpp
Normal file
116
.config/Code/User/History/5797a381/0UIr.cpp
Normal 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;
|
||||
}
|
86
.config/Code/User/History/5797a381/259Z.cpp
Normal file
86
.config/Code/User/History/5797a381/259Z.cpp
Normal 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;
|
||||
}
|
111
.config/Code/User/History/5797a381/2H9c.cpp
Normal file
111
.config/Code/User/History/5797a381/2H9c.cpp
Normal 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;
|
||||
}
|
71
.config/Code/User/History/5797a381/2eaO.cpp
Normal file
71
.config/Code/User/History/5797a381/2eaO.cpp
Normal 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;
|
||||
}
|
132
.config/Code/User/History/5797a381/6zST.cpp
Normal file
132
.config/Code/User/History/5797a381/6zST.cpp
Normal 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;
|
||||
}
|
77
.config/Code/User/History/5797a381/7IEa.cpp
Normal file
77
.config/Code/User/History/5797a381/7IEa.cpp
Normal 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;
|
||||
}
|
131
.config/Code/User/History/5797a381/8Twa.cpp
Normal file
131
.config/Code/User/History/5797a381/8Twa.cpp
Normal 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;
|
||||
}
|
133
.config/Code/User/History/5797a381/8ZkC.cpp
Normal file
133
.config/Code/User/History/5797a381/8ZkC.cpp
Normal 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;
|
||||
}
|
77
.config/Code/User/History/5797a381/Acme.cpp
Normal file
77
.config/Code/User/History/5797a381/Acme.cpp
Normal 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;
|
||||
}
|
73
.config/Code/User/History/5797a381/Byp6.cpp
Normal file
73
.config/Code/User/History/5797a381/Byp6.cpp
Normal 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;
|
||||
}
|
132
.config/Code/User/History/5797a381/CQdO.cpp
Normal file
132
.config/Code/User/History/5797a381/CQdO.cpp
Normal 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;
|
||||
}
|
92
.config/Code/User/History/5797a381/CZEH.cpp
Normal file
92
.config/Code/User/History/5797a381/CZEH.cpp
Normal 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;
|
||||
}
|
96
.config/Code/User/History/5797a381/EhP4.cpp
Normal file
96
.config/Code/User/History/5797a381/EhP4.cpp
Normal 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;
|
||||
}
|
131
.config/Code/User/History/5797a381/IQdm.cpp
Normal file
131
.config/Code/User/History/5797a381/IQdm.cpp
Normal 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;
|
||||
}
|
71
.config/Code/User/History/5797a381/IYSV.cpp
Normal file
71
.config/Code/User/History/5797a381/IYSV.cpp
Normal 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;
|
||||
}
|
134
.config/Code/User/History/5797a381/KHkg.cpp
Normal file
134
.config/Code/User/History/5797a381/KHkg.cpp
Normal 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;
|
||||
}
|
116
.config/Code/User/History/5797a381/KkMQ.cpp
Normal file
116
.config/Code/User/History/5797a381/KkMQ.cpp
Normal 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;
|
||||
}
|
133
.config/Code/User/History/5797a381/LJcN.cpp
Normal file
133
.config/Code/User/History/5797a381/LJcN.cpp
Normal 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;
|
||||
}
|
79
.config/Code/User/History/5797a381/MH8H.cpp
Normal file
79
.config/Code/User/History/5797a381/MH8H.cpp
Normal 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;
|
||||
}
|
92
.config/Code/User/History/5797a381/MNDW.cpp
Normal file
92
.config/Code/User/History/5797a381/MNDW.cpp
Normal 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;
|
||||
}
|
72
.config/Code/User/History/5797a381/OQgS.cpp
Normal file
72
.config/Code/User/History/5797a381/OQgS.cpp
Normal 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;
|
||||
}
|
135
.config/Code/User/History/5797a381/PNol.cpp
Normal file
135
.config/Code/User/History/5797a381/PNol.cpp
Normal 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;
|
||||
}
|
133
.config/Code/User/History/5797a381/Qzc1.cpp
Normal file
133
.config/Code/User/History/5797a381/Qzc1.cpp
Normal 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;
|
||||
}
|
132
.config/Code/User/History/5797a381/SrE1.cpp
Normal file
132
.config/Code/User/History/5797a381/SrE1.cpp
Normal 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;
|
||||
}
|
136
.config/Code/User/History/5797a381/UOso.cpp
Normal file
136
.config/Code/User/History/5797a381/UOso.cpp
Normal 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;
|
||||
}
|
127
.config/Code/User/History/5797a381/V3zR.cpp
Normal file
127
.config/Code/User/History/5797a381/V3zR.cpp
Normal 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;
|
||||
}
|
92
.config/Code/User/History/5797a381/VNZi.cpp
Normal file
92
.config/Code/User/History/5797a381/VNZi.cpp
Normal 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;
|
||||
}
|
129
.config/Code/User/History/5797a381/Zdr7.cpp
Normal file
129
.config/Code/User/History/5797a381/Zdr7.cpp
Normal 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;
|
||||
}
|
133
.config/Code/User/History/5797a381/ain2.cpp
Normal file
133
.config/Code/User/History/5797a381/ain2.cpp
Normal 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;
|
||||
}
|
133
.config/Code/User/History/5797a381/c9bR.cpp
Normal file
133
.config/Code/User/History/5797a381/c9bR.cpp
Normal 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;
|
||||
}
|
131
.config/Code/User/History/5797a381/cPvv.cpp
Normal file
131
.config/Code/User/History/5797a381/cPvv.cpp
Normal 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;
|
||||
}
|
92
.config/Code/User/History/5797a381/cyJI.cpp
Normal file
92
.config/Code/User/History/5797a381/cyJI.cpp
Normal 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;
|
||||
}
|
90
.config/Code/User/History/5797a381/d6pt.cpp
Normal file
90
.config/Code/User/History/5797a381/d6pt.cpp
Normal 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;
|
||||
}
|
1
.config/Code/User/History/5797a381/entries.json
Normal file
1
.config/Code/User/History/5797a381/entries.json
Normal 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}]}
|
86
.config/Code/User/History/5797a381/ewtW.cpp
Normal file
86
.config/Code/User/History/5797a381/ewtW.cpp
Normal 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;
|
||||
}
|
100
.config/Code/User/History/5797a381/goHP.cpp
Normal file
100
.config/Code/User/History/5797a381/goHP.cpp
Normal 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;
|
||||
}
|
129
.config/Code/User/History/5797a381/guY1.cpp
Normal file
129
.config/Code/User/History/5797a381/guY1.cpp
Normal 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;
|
||||
}
|
128
.config/Code/User/History/5797a381/iBTl.cpp
Normal file
128
.config/Code/User/History/5797a381/iBTl.cpp
Normal 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;
|
||||
}
|
131
.config/Code/User/History/5797a381/jRaE.cpp
Normal file
131
.config/Code/User/History/5797a381/jRaE.cpp
Normal 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;
|
||||
}
|
127
.config/Code/User/History/5797a381/mld0.cpp
Normal file
127
.config/Code/User/History/5797a381/mld0.cpp
Normal 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;
|
||||
}
|
131
.config/Code/User/History/5797a381/p5Gz.cpp
Normal file
131
.config/Code/User/History/5797a381/p5Gz.cpp
Normal 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;
|
||||
}
|
115
.config/Code/User/History/5797a381/pL11.cpp
Normal file
115
.config/Code/User/History/5797a381/pL11.cpp
Normal 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;
|
||||
}
|
124
.config/Code/User/History/5797a381/rOgn.cpp
Normal file
124
.config/Code/User/History/5797a381/rOgn.cpp
Normal 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;
|
||||
}
|
113
.config/Code/User/History/5797a381/sitg.cpp
Normal file
113
.config/Code/User/History/5797a381/sitg.cpp
Normal 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;
|
||||
}
|
92
.config/Code/User/History/5797a381/u4My.cpp
Normal file
92
.config/Code/User/History/5797a381/u4My.cpp
Normal 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;
|
||||
}
|
127
.config/Code/User/History/5797a381/uI1Q.cpp
Normal file
127
.config/Code/User/History/5797a381/uI1Q.cpp
Normal 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;
|
||||
}
|
132
.config/Code/User/History/5797a381/v6GZ.cpp
Normal file
132
.config/Code/User/History/5797a381/v6GZ.cpp
Normal 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;
|
||||
}
|
115
.config/Code/User/History/5797a381/vMGW.cpp
Normal file
115
.config/Code/User/History/5797a381/vMGW.cpp
Normal 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;
|
||||
}
|
129
.config/Code/User/History/5797a381/vxab.cpp
Normal file
129
.config/Code/User/History/5797a381/vxab.cpp
Normal 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;
|
||||
}
|
133
.config/Code/User/History/5797a381/yueQ.cpp
Normal file
133
.config/Code/User/History/5797a381/yueQ.cpp
Normal 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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue