123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973 |
- #include "arraylist.h"
- void initializeDemo() {
- printf("\n\t\t =============== START DEMO - initialize() =============== \n\n\n");
-
- printf("Initialising List a with initialize() \n\n");
- List *a = initialize();
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n\n", cap(a));
-
- printf("Appending 5, 9 \n\n");
- append(a, 5);
- append(a, 9);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n", cap(a));
-
- printf("\n\n\t\t =============== END DEMO - initialize() =============== \n\n\n");
- }
- void initializeWithCapacityDemo() {
- printf("\n\t\t =============== START DEMO - initializeWithCapacity() =============== \n\n\n");
-
- printf("Initialising List a with initializeWithCapacity(0) \n\n");
- List *a = initializeWithCapacity(0);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n\n", cap(a));
-
- printf("Appending 5, 4, 15, 9, 19 \n\n");
- append(a, 5);
- append(a, 4);
- append(a, 15);
- append(a, 9);
- append(a, 19);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n", cap(a));
-
- printf("\n\n\t\t =============== END DEMO - initializeWithCapacity() =============== \n\n\n");
- }
- void initializeWithArrayDemo() {
- printf("\n\t\t =============== START DEMO - initializeWithArray() =============== \n\n\n");
-
- printf("Initialising int arr[] with numbers from 1 to 18 \n\n");
- int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18};
-
- printf("Initialising List a with arr[] using initializeWithArray(arr, 18) \n\n");
- List *a = initializeWithArray(arr, 18);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n", cap(a));
-
- printf("\n\n\t\t =============== END DEMO - initializeWithArray() =============== \n\n\n");
- }
- void valuesDemo() {
- printf("\n\t\t =============== START DEMO - values() =============== \n\n\n");
-
- printf("Initialising List a with values(5, 1, 2, 5, 9, 17) \n\n");
- List *a = values(5, 1, 2, 5, 9, 17);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n", cap(a));
-
- printf("\n\n\t\t =============== END DEMO - values() =============== \n\n\n");
- }
- void rangeDemo() {
- printf("\n\t\t =============== START DEMO - range() =============== \n\n\n");
-
- printf("Initialising List a with range(0, 11, 2) \n\n");
- List *a = range(0, 11, 2);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n\n", cap(a));
-
- printf("Initialising List b with range(10, -1, -2) \n\n");
- List *b = range(10, -1, -2);
-
- printf("\t b = %s \n", toString(b));
- printf("\t Number of elements = %d \n", len(b));
- printf("\t Capacity of a = %d \n\n", cap(b));
-
- printf("toString( range(5, 51, 5) ) = %s \n", toString( range(5, 51, 5) ));
-
- printf("\n\n\t\t =============== END DEMO - range() =============== \n\n\n");
- }
- void sliceDemo() {
- printf("\n\t\t =============== START DEMO - slice() =============== \n\n\n");
-
- printf("Initialising List a with range(10, 21, 1) \n\n");
- List *a = range(10, 21, 1);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n\n", cap(a));
-
-
- printf("toString( slice(a, 2, 6, 1) ) = %s \n\n", toString( slice(a, 2, 6, 1) ));
- printf("toString( slice(a, 10, -1, -2) ) = %s \n\n", toString( slice(a, 10, -1, -2) ));
-
- printf("\n\n\t\t =============== END DEMO - slice() =============== \n\n\n");
- }
- void clearDemo() {
- printf("\n\t\t =============== START DEMO - clear() =============== \n\n\n");
-
- printf("Initialising List a with range(0, 11, 1) \n\n");
- List *a = range(0, 11, 1);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n\n", cap(a));
-
- printf("Removing all elements from List a using clear(a) \n\n");
- clear(a);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n\n", cap(a));
-
- printf("Appending 5 \n\n");
- append(a, 5);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n", cap(a));
-
- printf("\n\n\t\t =============== END DEMO - clear() =============== \n\n\n");
- }
- void ensureCapacityDemo() {
- printf("\n\t\t =============== START DEMO - ensureCapacity() =============== \n\n\n");
-
- printf("Initialising List a with range(0, 11, 2) \n\n");
- List *a = range(0, 11, 2);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n\n", cap(a));
-
- printf("Ensuring a minimum capacity of 2 using ensureCapacity(a, 2) \n\n");
- ensureCapacity(a, 2);
- printf("\t Capacity of a = %d \n\n", cap(a));
-
- printf("Ensuring a minimum capacity of 6 using ensureCapacity(a, 6) \n\n");
- ensureCapacity(a, 6);
- printf("\t Capacity of a = %d \n\n", cap(a));
-
- printf("Ensuring a minimum capacity of 7 using ensureCapacity(a, 7) \n\n");
- ensureCapacity(a, 7);
- printf("\t Capacity of a = %d \n\n", cap(a));
-
- printf("Ensuring a minimum capacity of 20 using ensureCapacity(a, 20) \n\n");
- ensureCapacity(a, 20);
- printf("\t Capacity of a = %d \n", cap(a));
-
- printf("\n\n\t\t =============== END DEMO - ensureCapacity() =============== \n\n\n");
- }
- void trimToSizeDemo() {
- printf("\n\t\t =============== START DEMO - trimToSize() =============== \n\n\n");
-
- printf("Initialising List a with initialize() \n\n");
- List *a = initialize();
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n\n", cap(a));
-
- printf("Initialising int arr[] with numbers from 1 to 6 \n\n");
- int arr[] = {1, 2, 3, 4, 5, 6};
-
- printf("Extending List a with arr[] using extendWithArray(a, arr, 6) \n\n");
- extendWithArray(a, arr, 6);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n\n", cap(a));
-
- printf("Trimming Unused Space in List a using trimToSize(a) \n\n");
- trimToSize(a);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n", cap(a));
-
- printf("\n\n\t\t =============== END DEMO - trimToSize() =============== \n\n\n");
- }
- void fillDemo() {
- printf("\n\t\t =============== START DEMO - fill() =============== \n\n\n");
-
- printf("Initialising List a with initialize() \n\n");
- List *a = initialize();
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n\n", cap(a));
-
- printf("Filling List a with 20 occurences of 5 using fill(a, 5, 20) \n\n");
- fill(a, 5, 20);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n\n", cap(a));
-
- printf("Filling List a with 7 occurences of 19 using fill(a, 19, 7) \n\n");
- fill(a, 19, 7);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n", cap(a));
-
- printf("\n\n\t\t =============== END DEMO - fill() =============== \n\n\n");
- }
- void appendDemo() {
- printf("\n\t\t =============== START DEMO - append() =============== \n\n\n");
-
- printf("Initialising List a with initializeWithCapacity(0) \n\n");
- List *a = initializeWithCapacity(0);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n\n", cap(a));
-
- printf("Appending 5, 4, 15, 9, 19 using append(a, n) \n\n");
- append(a, 5);
- append(a, 4);
- append(a, 15);
- append(a, 9);
- append(a, 19);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n", cap(a));
-
- printf("\n\n\t\t =============== END DEMO - append() =============== \n\n\n");
- }
- void extendWithArrayDemo() {
- printf("\n\t\t =============== START DEMO - extendWithArray() =============== \n\n\n");
-
- printf("Initialising List a with range(0, 11, 2) \n\n");
- List *a = range(0, 11, 2);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n\n", cap(a));
-
- printf("Initialising int arr[] with numbers from 1 to 6 \n\n");
- int arr[] = {1, 2, 3, 4, 5, 6};
-
- printf("Extending List a with arr[] using extendWithArray(a, arr, 6) \n\n");
- extendWithArray(a, arr, 6);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n", cap(a));
-
- printf("\n\n\t\t =============== END DEMO - extendWithArray() =============== \n\n\n");
- }
- void extendDemo() {
- printf("\n\t\t =============== START DEMO - extend() =============== \n\n\n");
-
- printf("Initialising List a with range(0, 11, 2) \n\n");
- List *a = range(0, 11, 2);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n\n", cap(a));
-
- printf("Initialising List b with range(1, 11, 2) \n\n");
- List *b = range(1, 11, 2);
-
- printf("\t b = %s \n", toString(b));
- printf("\t Number of elements = %d \n", len(b));
- printf("\t Capacity of b = %d \n\n", cap(b));
-
- printf("Extending List a with List b using extend(a, b) \n\n");
- extend(a, b);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n\n", cap(a));
-
- printf("Extending List a using extend(a, range(90, 96, 2)) \n\n");
- extend(a, range(90, 96, 2));
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n", cap(a));
-
- printf("\n\n\t\t =============== END DEMO - extend() =============== \n\n\n");
- }
- void insertDemo() {
- printf("\n\t\t =============== START DEMO - insert() =============== \n\n\n");
-
- printf("Initialising List a with range(0, 10, 1) \n\n");
- List *a = range(0, 10, 1);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n\n", cap(a));
-
- printf("Inserting 99 at 0th index using insert(a, 0, 99) \n\n");
- insert(a, 0, 99);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n\n", cap(a));
-
- printf("Inserting 88 at the end using insert(a, len(a), 88) \n\n");
- insert(a, len(a), 88);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n\n", cap(a));
-
- printf("Inserting 55 at 5th index using insert(a, 5, 55) \n\n");
- insert(a, 5, 55);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n\n", cap(a));
-
- printf("Inserting 22 at the last index using insert(a, -1, 22) \n\n");
- insert(a, -1, 22);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n", cap(a));
-
- printf("\n\n\t\t =============== END DEMO - insert() =============== \n\n\n");
- }
- void copyDemo() {
- printf("\n\t\t =============== START DEMO - copy() =============== \n\n\n");
-
- printf("Initialising List a with range(0, 10, 2) \n\n");
- List *a = range(0, 10, 2);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n\n", cap(a));
-
- printf("Initialising List b with copy(a) \n\n");
- List *b = copy(a);
-
- printf("\t b = %s \n", toString(b));
- printf("\t Number of elements = %d \n", len(b));
- printf("\t Capacity of b = %d \n", cap(b));
-
- printf("\n\n\t\t =============== END DEMO - copy() =============== \n\n\n");
- }
- void indexOfDemo() {
- printf("\n\t\t =============== START DEMO - indexOf() =============== \n\n\n");
-
- printf("Initialising List a with range(0, 11, 2) \n\n");
- List *a = range(0, 11, 2);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n\n", cap(a));
-
- printf("Searching for the first occurrence of numbers from 0 to 10 using indexOf(a, i) \n\n");
- for(int i = 0; i < 11; i++) {
- int index = indexOf(a, i);
- if(index < 0)
- printf("\t %d not found in a \n", i);
- else
- printf("\t %d found at index %d \n", i, index);
- }
-
- printf("\n\n\t\t =============== END DEMO - indexOf() =============== \n\n\n");
- }
- void lastIndexOfDemo() {
- printf("\n\t\t =============== START DEMO - lastIndexOf() =============== \n\n\n");
-
- printf("Initialising int arr[] with {0, 1, 2, 2, 3, 4, 5, 6, 2, 7, 8, 9} \n\n");
- int arr[] = {0, 1, 2, 2, 3, 4, 5, 6, 2, 7, 8, 9};
-
- printf("Initialising List a with arr[] using initializeWithArray(arr, 12) \n\n");
- List *a = initializeWithArray(arr, 12);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n\n", cap(a));
-
- printf("Searching for the last occurrence of 2, 10 using lastIndexOf(a, i) \n\n");
- printf("\t Last index of 2 = %d \n", lastIndexOf(a, 2));
- printf("\t Last index of 10 = %d \n", lastIndexOf(a, 10));
-
- printf("\n\n\t\t =============== END DEMO - lastIndexOf() =============== \n\n\n");
- }
- void binarySearchDemo() {
- printf("\n\t\t =============== START DEMO - binarySearch() =============== \n\n\n");
-
- printf("Initialising List a with range(0, 11, 2) \n\n");
- List *a = range(0, 11, 2);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n\n", cap(a));
-
- printf("Searching for the index of numbers from 0 to 10 using binarySearch(a, i) \n\n");
- for(int i = 0; i < 11; i++) {
- int index = binarySearch(a, i);
- if(index < 0)
- printf("\t %d not found in a \n", i);
- else
- printf("\t %d found at index %d \n", i, index);
- }
-
- printf("\n\n\t\t =============== END DEMO - binarySearch() =============== \n\n\n");
- }
- void containsDemo() {
- printf("\n\t\t =============== START DEMO - contains() =============== \n\n\n");
-
- printf("Initialising List a with range(0, 11, 2) \n\n");
- List *a = range(0, 11, 2);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n\n", cap(a));
-
- printf("Checking for the presence of numbers from 0 to 10 using contains(a, i) \n\n");
- for(int i = 0; i < 11; i++) {
- if(contains(a, i))
- printf("\t a contains %d \n", i);
- else
- printf("\t a doesn't contain %d \n", i);
- }
-
- printf("\n\n\t\t =============== END DEMO - contains() =============== \n\n\n");
- }
- void isEmptyDemo() {
- printf("\n\t\t =============== START DEMO - isEmpty() =============== \n\n\n");
-
- printf("Initialising List a with range(0, 11, 1) \n\n");
- List *a = range(0, 11, 1);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n\n", cap(a));
-
- printf("Checking if a is empty using isEmpty(a) \n\n");
- if(isEmpty(a))
- printf("\t a is empty \n\n");
- else
- printf("\t a is not empty \n\n");
-
- printf("Removing all elements from List a using clear(a) \n\n");
- clear(a);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n\n", cap(a));
-
- printf("Checking if a is empty using isEmpty(a) \n\n");
- if(isEmpty(a))
- printf("\t a is empty \n");
- else
- printf("\t a is not empty \n");
-
- printf("\n\n\t\t =============== END DEMO - isEmpty() =============== \n\n\n");
- }
- void isEqualDemo() {
- printf("\n\t\t =============== START DEMO - isEqual() =============== \n\n\n");
-
- printf("Initialising List a with range(0, 10, 2) \n\n");
- List *a = range(0, 10, 2);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n\n", cap(a));
-
- printf("Initialising List b with copy(a) \n\n");
- List *b = copy(a);
-
- printf("\t b = %s \n", toString(b));
- printf("\t Number of elements = %d \n", len(b));
- printf("\t Capacity of b = %d \n\n", cap(b));
-
- printf("Checking if List a is equal to List b using isEqual(a, b) \n\n");
- if(isEqual(a, b))
- printf("\t a is equal to b \n\n");
- else
- printf("\t a is not equal to b \n\n");
-
- printf("Appending 0 to List b using append(b, 0) \n\n");
- append(b, 0);
-
- printf("\t b = %s \n", toString(b));
- printf("\t Number of elements = %d \n", len(b));
- printf("\t Capacity of b = %d \n\n", cap(b));
-
- printf("Checking if List a is equal to List b using isEqual(a, b) \n\n");
- if(isEqual(a, b))
- printf("\t a is equal to b \n\n");
- else
- printf("\t a is not equal to b \n\n");
-
- printf("Appending 0 to List a using append(a, 0) \n\n");
- append(a, 0);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n\n", cap(a));
-
- printf("Checking if List a is equal to List b using isEqual(a, b) \n\n");
- if(isEqual(a, b))
- printf("\t a is equal to b \n");
- else
- printf("\t a is not equal to b \n");
-
- printf("\n\n\t\t =============== END DEMO - isEqual() =============== \n\n\n");
- }
- void popDemo() {
- printf("\n\t\t =============== START DEMO - pop() =============== \n\n\n");
-
- printf("Initialising List a with range(0, 11, 1) \n\n");
- List *a = range(0, 11, 1);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n\n", cap(a));
-
- printf("Removing first element of a using pop(a, 0) \n\n");
- pop(a, 0);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n\n", cap(a));
-
- printf("Removing last element of a using pop(a, -1) \n\n");
- pop(a, -1);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n\n", cap(a));
-
- printf("Trying to remove value at index 10 from a using pop(a, 10) \n\n");
- if(pop(a, 10))
- printf("\t a = %s \n\n", toString(a));
- else
- printf("\t index %d not found in a \n\n", 10);
-
- printf("Trying to remove value at index 2 from a using pop(a, 2) \n\n");
- if(pop(a, 2))
- printf("\t a = %s \n\n", toString(a));
- else
- printf("\t index %d not found in a \n\n", 10);
-
- printf("Removing value at 2nd last index using pop(a, -2) \n\n");
- pop(a, -2);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n", cap(a));
-
- printf("\n\n\t\t =============== END DEMO - pop() =============== \n\n\n");
- }
- void deleteDemo() {
- printf("\n\t\t =============== START DEMO - delete() =============== \n\n\n");
-
- printf("Initialising List a with range(0, 11, 2) \n\n");
- List *a = range(0, 11, 2);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n\n", cap(a));
-
- printf("Trying to delete numbers from 0 to 10 using delete(a, i) \n\n");
- for(int i = 0; i < 11; i++) {
- if(delete(a, i))
- printf("\t %d deleted from a \n", i);
- else
- printf("\t a doesn't contain %d \n", i);
- }
- printf("\n");
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n", cap(a));
-
- printf("\n\n\t\t =============== END DEMO - delete() =============== \n\n\n");
- }
- void getDemo() {
- printf("\n\t\t =============== START DEMO - get() =============== \n\n\n");
-
- printf("Initialising List a with range(0, 11, 2) \n\n");
- List *a = range(0, 11, 2);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n\n", cap(a));
-
- printf("Trying to print the values at indexes 0 to 10 using get(a, i) \n\n");
- for(int i = 0; i < 11; i++) {
- printf("\t Value at index %d = %d \n", i, get(a, i));
- }
-
- printf("\n\n\t\t =============== END DEMO - get() =============== \n\n\n");
- }
- void setDemo() {
- printf("\n\t\t =============== START DEMO - set() =============== \n\n\n");
-
- printf("Initialising List a with range(0, 11, 2) \n\n");
- List *a = range(0, 11, 2);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n\n", cap(a));
-
- printf("Trying to double the value of all elements using set(a, i, get(a, i) * 2) \n\n");
- for(int i = 0; i < 11; i++) {
- if(set(a, i, get(a, i) * 2))
- printf("\t Doubling value at index %d successful \n", i);
- else
- printf("\t Index %d not found \n", i);
- }
- printf("\n");
-
- printf("a after doubling \n\n");
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n", cap(a));
-
- printf("\n\n\t\t =============== END DEMO - set() =============== \n\n\n");
- }
- void reverseDemo() {
- printf("\n\t\t =============== START DEMO - reverse() =============== \n\n\n");
-
- printf("Initialising List a with range(0, 11, 1) \n\n");
- List *a = range(0, 11, 1);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n\n", cap(a));
-
- printf("Reversing the order of elements using reverse(a) \n\n");
- reverse(a);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n", cap(a));
-
- printf("\n\n\t\t =============== END DEMO - reverse() =============== \n\n\n");
- }
- void replaceDemo() {
- printf("\n\t\t =============== START DEMO - replace() =============== \n\n\n");
-
- printf("Initialising int arr[] with {0, 1, 2, 3, 4, 5, 6, 1, 2, 2, 3, 4, 2, 6, 2} \n\n");
- int arr[] = {0, 1, 2, 3, 4, 5, 6, 1, 2, 2, 3, 4, 2, 6, 2};
-
- printf("Initialising List a with arr[] using initializeWithArray(arr, 15) \n\n");
- List *a = initializeWithArray(arr, 15);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n\n", cap(a));
-
- printf("Replacing all occurrences of 2 with 99 using replace(a, 2, 99) \n\n");
- replace(a, 2, 99);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n", cap(a));
-
- printf("\n\n\t\t =============== END DEMO - replace() =============== \n\n\n");
- }
- void sortDemo() {
- printf("\n\t\t =============== START DEMO - sort() =============== \n\n\n");
-
- printf("Initialising List a with range(0, 11, 2) \n\n");
- List *a = range(0, 11, 2);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n\n", cap(a));
-
- printf("Extending List a using extend(a, range(1, 11, 2)) \n\n");
- extend(a, range(1, 11, 2));
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n\n", cap(a));
-
- printf("Sorting the elements of a in increasing order using sort(a) \n\n");
- sort(a);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n", cap(a));
-
- printf("\n\n\t\t =============== END DEMO - sort() =============== \n\n\n");
- }
- void sortReverseDemo() {
- printf("\n\t\t =============== START DEMO - sortReverse() =============== \n\n\n");
-
- printf("Initialising List a with range(0, 11, 2) \n\n");
- List *a = range(0, 11, 2);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n\n", cap(a));
-
- printf("Extending List a using extend(a, range(1, 11, 2)) \n\n");
- extend(a, range(1, 11, 2));
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n\n", cap(a));
-
- printf("Sorting the elements of a in increasing order using sortReverse(a) \n\n");
- sortReverse(a);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n", cap(a));
-
- printf("\n\n\t\t =============== END DEMO - sortReverse() =============== \n\n\n");
- }
- void countDemo() {
- printf("\n\t\t =============== START DEMO - count() =============== \n\n\n");
-
- printf("Initialising int arr[] with {1, 2, 2, 3, 3, 3, 5, 5, 5, 5} \n\n");
- int arr[] = {1, 2, 2, 3, 3, 3, 5, 5, 5, 5};
-
- printf("Initialising List a with arr[] using initializeWithArray(arr, 10) \n\n");
- List *a = initializeWithArray(arr, 10);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n\n", cap(a));
-
- printf("Counting the frequency of numbers from 0 to 5 using count(a, i) \n\n");
- for(int i = 0; i <= 5; i++)
- printf("\t %d is present %d times \n", i, count(a, i));
-
- printf("\n\n\t\t =============== END DEMO - count() =============== \n\n\n");
- }
- void sumDemo() {
- printf("\n\t\t =============== START DEMO - sum() =============== \n\n\n");
-
- printf("Initialising List a with range(0, 11, 2) \n\n");
- List *a = range(0, 11, 2);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n\n", cap(a));
-
- printf("Calculating sum of all elements of a using sum(a) \n\n");
- printf("\t Sum(a) = %d \n", sum(a));
-
- printf("\n\n\t\t =============== END DEMO - sum() =============== \n\n\n");
- }
- void lenDemo() {
- printf("\n\t\t =============== START DEMO - len() =============== \n\n\n");
-
- printf("Initialising List a with range(0, 11, 2) \n\n");
- List *a = range(0, 11, 2);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n\n", cap(a));
-
- printf("Appending 5, 9 \n\n");
- append(a, 5);
- append(a, 9);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Capacity of a = %d \n\n", cap(a));
-
- printf("Finding new length of a using len(a) \n\n");
- printf("\t Len(a) = %d \n", len(a));
-
- printf("\n\n\t\t =============== END DEMO - len() =============== \n\n\n");
- }
- void capDemo() {
- printf("\n\t\t =============== START DEMO - cap() =============== \n\n\n");
-
- printf("Initialising List a with range(0, 11, 2) \n\n");
- List *a = range(0, 11, 2);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n\n", cap(a));
-
- printf("Appending 5 \n\n");
- append(a, 5);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n\n", len(a));
-
- printf("Finding new capacity of a using cap(a) \n\n");
- printf("\t Cap(a) = %d \n", cap(a));
-
- printf("\n\n\t\t =============== END DEMO - cap() =============== \n\n\n");
- }
- void toArrayDemo() {
- printf("\n\t\t =============== START DEMO - toArray() =============== \n\n\n");
-
- printf("Initialising List a with range(0, 11, 2) \n\n");
- List *a = range(0, 11, 2);
-
- printf("\t a = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n\n", cap(a));
-
- printf("Initialising int arr[] with elements of List a using toArray(a) \n\n");
- int *arr = toArray(a);
- int arrLength = len(a);
-
- printf("\t arr[] = ");
- for(int i = 0; i < arrLength; i++)
- printf("%d ", arr[i]);
- printf("\n");
-
- printf("\n\n\t\t =============== END DEMO - toArray() =============== \n\n\n");
- }
- void toStringDemo() {
- printf("\n\t\t =============== START DEMO - toString() =============== \n\n\n");
-
- printf("Initialising List a with range(1000000000, 1000000009, 1) \n\n");
- List *a = range(1000000000, 1000000009, 1);
-
- printf("\t toString(a) = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n\n", cap(a));
-
- printf("Appending 1111111111 \n\n");
- append(a, 1111111111);
-
- printf("\t toString(a) = %s \n", toString(a));
- printf("\t Number of elements = %d \n", len(a));
- printf("\t Capacity of a = %d \n", cap(a));
-
- printf("\n\n\t\t =============== END DEMO - toString() =============== \n\n\n");
- }
- void displayDemo() {
- printf("\n\t\t =============== START DEMO - display() =============== \n\n\n");
-
- printf("Initialising List a with range(0, 11, 2) \n\n");
- List *a = range(0, 11, 2);
-
- printf("Displaying the elements of a using display(a) \n\n");
- printf("\t ");
- display(a);
- printf("\n");
-
- printf("Appending 5 \n\n");
- append(a, 5);
-
- printf("Displaying the elements of a using display(a) \n\n");
- printf("\t ");
- display(a);
-
- printf("\n\n\t\t =============== END DEMO - display() =============== \n\n\n");
- }
- int main(void) {
-
- initializeDemo();
-
- initializeWithCapacityDemo();
-
- initializeWithArrayDemo();
-
- valuesDemo();
-
- rangeDemo();
-
- sliceDemo();
-
- clearDemo();
-
- ensureCapacityDemo();
-
- trimToSizeDemo();
-
- fillDemo();
-
- appendDemo();
-
- extendWithArrayDemo();
-
- extendDemo();
-
- insertDemo();
-
- copyDemo();
-
- indexOfDemo();
-
- lastIndexOfDemo();
-
- binarySearchDemo();
-
- containsDemo();
-
- isEmptyDemo();
-
- isEqualDemo();
-
- popDemo();
-
- deleteDemo();
-
- getDemo();
-
- setDemo();
-
- reverseDemo();
-
- replaceDemo();
-
- sortDemo();
-
- sortReverseDemo();
-
- countDemo();
-
- sumDemo();
-
- lenDemo();
-
- capDemo();
-
- toArrayDemo();
-
- toStringDemo();
-
- displayDemo();
-
- return 0;
- }
|