In this assignment, you will be working with arrays in C. The goal is to write a program that can insert elements into an array at the end, the beginning, and at a specified index. This will help you understand basic array manipulations and enhance your problem-solving skills in C programming.
You will be provided with a partially completed code file. Your task is to complete the functions in the code that handle the insertion operations.
- Task: Complete the
insertAtEnd
function. - Details: You need to insert a user-specified element at the end of the pre-populated array.
- Task: Complete the
insertAtBeginning
function. - Details: You need to insert a user-specified element at the beginning of the pre-populated array, shifting all existing elements to the right.
- Task: Complete the
insertAtIndex
function. - Details: You need to insert a user-specified element at a given index in the array, shifting the elements from that index onward to the right.
-
Open the provided
.c
file:- This file contains the main program structure and partially completed functions. Your task is to fill in the missing code within the
insertAtEnd
,insertAtBeginning
, andinsertAtIndex
functions.
- This file contains the main program structure and partially completed functions. Your task is to fill in the missing code within the
-
Read the comments:
- Each function contains comments that guide you on what needs to be done. Follow the instructions carefully to complete the functions.
-
Test your code:
- The code file includes test functions that will be executed to check if your implementation is correct. Run the program and verify that the output matches the expected results.
-
Run the tests:
- To verify the correctness of your implementation, you can run the provided
test.sh
script. This script will compile your code and run test cases to ensure your functions work as expected.
- To verify the correctness of your implementation, you can run the provided
-
Compile your program:
- Run the following command in your terminal to compile the program:
gcc -o array_insert_solution_modular array_insert_solution_modular.c
- Run the following command in your terminal to compile the program:
-
Run the test script:
- Execute the test script to check your code:
bash test.sh
- The script will report whether each of your functions passed the test cases.
- Execute the test script to check your code:
-
Review the results:
- If any tests fail, review your code and make the necessary corrections. Once all tests pass, your assignment is complete.
Once you’ve completed and tested your program, commit your changes and push them to the repository. Ensure that your code is correctly formatted and includes any necessary comments explaining your logic.