Introduction
This article shows how to create array dynamically with int and string index .
Background
This article assumes you are familiar with Link List and operator overloading in C++.because it is totally build on this knowledge. subscript operaotor is overloaded so we can create array dynamically and to know whether this subscript operator is on Left hand side ot right hand side we have created another class name ArrayItem that is maintaining link list and we have overloaded int,char* and double type etc.. so we can identify this is right hand side value . the version of subscript operator with const keyword that we used for right hand side value was not working. so i use different style mention above. i have made different function so this class could look useful others can also add function to this class an let me know to update this article.
Using the code
NewDynamicArray<int> NDA ;
NDA["asd"]=1;
int i=NDA["asd"];
NDA[1]=3;
printf("%d",(int)NDA["murtza"]);
NDA[1]=2;
i=NDA[1];
while(NDA.MoveNext())
printf("%s",(int)NDA.Ite->value);
NDA.ReSetIterator();
NewDynamicArray<char*> NDa;
NDa["age"]="twenty one";
NDa["dob"]="07-aug-1985";
NDa["age"]="08-aug-1985";
printf("%s",(char*)NDa["dob"]);
>These are the functions of NewDynamicArray Class .
void Insert(const int index,const Type& T);
this function inserts the value in array .if index exist already than overwrites existing value.this inserts function takes index of type int;
void Insert(char* index,const Type& T);
this function inserts the value in array .if index exist already than
overwrites existing value.this inserts function takes index of type string(char*);
bool IsIndexExist(int index);
This Function Checks whether given index exist already or not .this function takes index of type int;
bool IsIndexExist(char* index);
This Function Checks whether given index exist already or not .this function takes index of type int;
Type& Get(const int index);
This functions get the value of given index .this is functions is for index of type int.
Type& Get(const char* index);
This functions get the value of given index .this is functions is for index of type string.
bool IsValueExist(Type value);
This Function Checks whether given Value exist already or not .
void RemoveByIndex(char* index);
This Function Remove Value by Index of type string.
void RemoveByIndex(int index);
This Function Remove Value by Index of type itn.
void RemoveByValue(Type value);
This Function Remove Value by input Value.
bool MoveNext();
This function is to iterate the link list so we can access value.
void ReSetIterator();
this function is to reset iterator .so iterator can point to first value.
This class can be very useful any many ways
1)Index of any type string or int can be created .
2)Value can be retrieve easily and flexibly.
3)User can also include their own functions.
4)This is template class any data type can be use
.