You are on page 1of 5

NFC Institute of Engineering&Fertilizer

Research Faisalabad

Department of Electrical Engineering


Fourth Semester
Course Title:
Data Structure & Algorithms (EE-232)
Topic:
Lab Assignments
Submitted To:
Dr. Salman Arain
Submitted By:
Hafeez Ali
Roll.No:
18-ELE-43
Reg.#:
2018-UET-NFC-FD-ELECT-43
Lab.No.1
OPERATION OF LINEAR ARRAY
Task#1
Write a function to create an array.
C Function:
int createArray( arraySize )
{
int n[ arraySize ];
int i;

printf("Enter %d integers: ", arraySize);

for(int i = 0; i < arraySize; ++i) {


scanf("%d", &n[i]);
}
}

Task#2
Write a function to transverse an array.
C Function:
void printArray(int* array, int arraySize)
{
int i;

printf("Array: ");

for (i = 0; i < arraySize; i++) {


printf("%d ", array[i]);
}
}
Task#3
Write a function to insert elements in beginning of an array.
C Function:
int insetElement(int* array, int n) // n is number of elements
{
int value, c;
printf("Enter the value you want to insert: ");
scanf("%d", &value);

for (c = n-1; c >= 0; c--) {


array[c+1] = array[c];
}
array[0] = value;
}

Task#4
Write a function to insert elements in mid of an array.
C Function:
int insetElement(int* array, int n) // n is number of elements
{
int value, c, mid;
mid = n/2;

printf("Enter the value you want to insert: ");


scanf("%d", &value);

for (c = n-1; c >= mid-1; c--) {


array[c+1] = array[c];
}
array[mid-1] = value;
}
Task#5
Write a function to insert elements at the end of an array.
C Function:

int insetElement(int* array, int n) // n is number of elements


{
int value, c;

printf("Enter the value you want to insert: ");

scanf("%d", &value);

array[n] = value;

Task#6
Write a function to delete elements in beginning of an array.
C Function:

int deleteElement(int* array, int n) // n is number of elements


{
int c;

for (c = 0; c < n - 1; c++) {


array[c] = array[c+1];
}

}
Task#7
Write a function to delete elements in mid of an array.
C Function:

int deleteElement(int* array, int n) // n is number of elements


{
int c;

mid = n/2;

for (c = mid-1; c < n - 1; c++) {


array[c] = array[c+1];
}
}

Task#8
Write a function to delete elements at the end of an array.
C Function:
int deleteElement(int* array, int n) // n is number of elements
{
int c;

array[n-1] = array[n];
}

Conclusion:
In this lab, I came to know how to create array using function, how to
transvers it and different operations on array such as:
1. Insertion
2. Deletion

You might also like