0% found this document useful (0 votes)
54 views

Fourth Semester Department of Electrical Engineering

This document summarizes 8 tasks completed as part of a lab assignment on data structures and algorithms. The tasks involve writing C functions to: 1) Create an array, 2) Transverse an array, 3) Insert elements at the beginning, middle, and end of an array, 4) Delete elements at the beginning, middle, and end of an array. The conclusion states the lab helped learn how to create arrays using functions and perform different operations like insertion and deletion on arrays.

Uploaded by

Hafeez Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views

Fourth Semester Department of Electrical Engineering

This document summarizes 8 tasks completed as part of a lab assignment on data structures and algorithms. The tasks involve writing C functions to: 1) Create an array, 2) Transverse an array, 3) Insert elements at the beginning, middle, and end of an array, 4) Delete elements at the beginning, middle, and end of an array. The conclusion states the lab helped learn how to create arrays using functions and perform different operations like insertion and deletion on arrays.

Uploaded by

Hafeez Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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