Professional Documents
Culture Documents
Submission By: Author of Code: Kshitij Kumar Singh Chauhan Language: C++ 17 Compiler Used For Testing: G++
Submission By: Author of Code: Kshitij Kumar Singh Chauhan Language: C++ 17 Compiler Used For Testing: G++
README
INITIALIZE
1. Fill all : fill list completely.
2. Get element from position : return an element from the list at any given position.
3. Reinitialize to empty : reinitialize list as empty
INSERTION
4. Insert element at position : insert a new element at any position of the list.
5. Insert at end : insert a new element at the end of the list.
DELETION
6. Remove a given element : remove the first occurrence of any element from a non-empty list.
7. Remove element at given position : remove the element at a specified location from a non-empty list.
SEARCHING
8. Search an element : search an element and return position, if found.
9. Search and Replace an element with another element : replace an element by another element.
PRINTING
10. Print all : print complete list
11. Print after a position : print elements after a certain position.
12. Print till a position : print elements till a certain position.
13. Print in range : print elements in an interval of positions.
MISCELLANEOUS
14. Tell current size : return the number of elements in the list.
15. Is my list empty ? : return true if the list is empty, otherwise return false
16. Is my list full ? : return true if the list is full, otherwise return false
17. Exit
LIST OF FIGURES
Fig 1. Execution
OPERATIONS TO INSERTION
Fig 8. Insert element at position (a)
Fig 9. Insert element at position (b)
Fig 10. Insert element at end (a)
Fig 10. Insert element at end (b)
MISCELLANEOUS OPERATIONS
Fig 27. Tell current size (a)
Fig 28. Tell current size (b)
Fig 29. Is my list empty ? (a)
Fig 30. Is my list empty ? (b)
Fig 31. Is my list full ? (a)
Fig 32. Is my list full ? (b)
SOURCE CODE
#include<iostream>
//set of functions
//MISCELLANEOUS
void tell_size(int current_size, int size) //f1
{
std::cout<<"Total size : "<<size<<"\n";
std::cout<<"Used size : "<<current_size<<"\n";
std::cout<<"Available size : "<<(size - current_size)<<"\n";
}
//INITIALIZATION
void fill_all(int my_list[], int ¤t_size, int size) //f4
{
int run_again = 1;
while(run_again == 1)
{
if(!is_empty(current_size, size))
{
int choice = 0;
std::cout<<"List already has some elements\n";
std::cout<<"Continuing will overwrite those elements\n";
std::cout<<"Press 1 if you still wish to continue (else press anyother
number) : ";
std::cin>>choice;
std::cout<<"\n";
if(choice != 1)
return;
}
current_size = size;
int pos;
std::cout<<"Which position do you wish to access (enter position)? : ";
std::cin>>pos;
std::cout<<"\n";
if( pos < 1)
std::cout<<"Position must be greater than 0\n";
else if(pos > current_size)
std::cout<<"Position must be less than current size of list\n";
else
std::cout<<"Element present at position "<<pos<<" is : "<<my_list[pos-
1]<<"\n";
current_size = 0;
}
//INSERTION
void insert_at_pos(int my_list[], int ¤t_size, int size) //f7
{
int run_again = 1;
while(run_again == 1)
{
if(is_full(current_size, size))
return;
int insert_it;
std::cout<<"What to insert (enter value)? : ";
std::cin>>insert_it;
std::cout<<"\n";
my_list[current_size] = insert_it;
current_size++;
//DELETION
void remove_by_val(int my_list[], int ¤t_size, int size) //f9
{
int run_again = 1;
while(run_again == 1)
{
if(is_empty(current_size, size))
return;
if(found == 0)
std::cout<<"Not Found\n";
if(remove_from < 1)
std::cout<<"Value of remove from must be greater tha 1\n";
else if(remove_from > current_size)
std::cout<<"Position "<<remove_from<<" is already empty\n";
else
{
std::cout<<my_list[remove_from-1]<<" present at position
"<<remove_from<<" has been removed\n";
for(int i = remove_from-1; i< current_size-1; i++)
my_list[i] = my_list[i+1];
current_size--;
}
//SEARCHING
void search_by_val(int my_list[], int current_size, int size) //f11
{
int run_again = 1;
while(run_again == 1)
{
if(is_empty(current_size, size))
return;
//PRINTING
void print_all(int my_list[], int current_size, int size) //f13
{
int run_again = 1;
while(run_again == 1)
{
if(is_empty(current_size, size))
return;
//main
int main()
{
int size; // specifies size of list to be declared
std::cout<<"Enter the size of list to be created : ";
std::cin>>size;
int my_list[size]; // declared a list of integers with size as provided by
user
std::cout<<"\nINSERTION\n";
std::cout<<"4. Insert element at position\n"; //insert a new element at
any position of the list.
std::cout<<"5. Insert at end\n"; //insert a new element at the end of the
list.
std::cout<<"\nDELETION\n";
std::cout<<"6. Remove a given element\n"; //remove the first occurrence of
any element from a non empty list.
std::cout<<"7. Remove element at given position\n"; //remove the element
at a specified location from a non empty list.
std::cout<<"\nSEARCHING\n";
std::cout<<"8. Search an element\n"; //search an element and return
position, if found.
std::cout<<"9. Search and Replace an element with other element\n";
//replace an element by another element.
std::cout<<"\nPRINTING-\n";
std::cout<<"10. Print all\n"; //print complete list
std::cout<<"11. Print after a position\n"; //print elements after a
certain position.
std::cout<<"12. Print till a position\n"; // print elements till a certain
position.
std::cout<<"13. Print in range\n"; // print elements in an interval of
positions.
std::cout<<"\nMISCELLANEOUS\n";
std::cout<<"14. Tell current size\n"; //return the number of elements in
the list.
std::cout<<"15. Is my list empty ?\n"; //return true if the list is empty,
otherwise return false
std::cout<<"16. Is my list full ?\n"; //return true if the list is full,
otherwise return false
std::cout<<"17. Exit\n";
std::cout<<"\n";
switch(choice)
{
case 1 :
fill_all(my_list, current_size, size);
break;
case 2 :
get_from_pos(my_list, current_size, size);
break;
case 3 :
make_empty(current_size, size);
break;
case 4 :
insert_at_pos(my_list, current_size, size);
break;
case 5 :
insert_at_end(my_list, current_size, size);
break;
case 6 :
remove_by_val(my_list, current_size, size);
break;
case 7 :
remove_by_pos(my_list, current_size, size);
break;
case 8 :
search_by_val(my_list, current_size, size);
break;
case 9 :
search_and_replace(my_list, current_size, size);
break;
case 10 :
print_all(my_list, current_size, size);
break;
case 11 :
print_after(my_list, current_size, size);
break;
case 12 :
print_till(my_list, current_size, size);
break;
case 13 :
print_in_range(my_list, current_size, size);
break;
case 14 :
tell_size(current_size, size);
break;
case 15 :
is_empty(current_size, size);
break;
case 16 :
is_full(current_size, size);
break;
case 17 :
std::cout<<"Terminating...\n";
exit(0);
default :
std::cout<<"Invalid choice | Given choice not found in set of
available operations";
return 0;
}
SAMPLE OUTPUTS
NOTE
Following outputs have been classified into operations
as listed in available utilities. Outputs have been split
into multiple figures, wherever considered necessary, to
demonstrate different aspects of operations. List of
figures provided above may be used to navigate to
sample output of desired operation.
Fig 1. Execution
Fig 2. Fill all (a)
Fig 18. Search and replace element with a given element (a)
Fig 19. Search and replace element with a given element (b)
Fig 20. Print all