0% found this document useful (0 votes)
42 views4 pages

Experiment 2: To Manipulate Arrays For Solving Various Searching and Sorting Problems in C++

This lab manual covers experiments on manipulating arrays in C++. The objectives are to create and manipulate array data structures. The tasks include: 1) swapping values between two arrays, 2) finding the second maximum and minimum values of an array, 3) finding common elements between two arrays, 4) swapping contents of two dynamic arrays, and 5) finding a triplet in an array that sums to a given number. The focus is on applying array concepts and data structures.

Uploaded by

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

Experiment 2: To Manipulate Arrays For Solving Various Searching and Sorting Problems in C++

This lab manual covers experiments on manipulating arrays in C++. The objectives are to create and manipulate array data structures. The tasks include: 1) swapping values between two arrays, 2) finding the second maximum and minimum values of an array, 3) finding common elements between two arrays, 4) swapping contents of two dynamic arrays, and 5) finding a triplet in an array that sums to a given number. The focus is on applying array concepts and data structures.

Uploaded by

Nomi Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Lab Manual of ‘Data Structures and Algorithms’

EXPERIMENT 2 Date Perform:


_________

To manipulate arrays for solving various searching and sorting


problems in C++

OBJECTIVE:
• Creating Array data structure
• Manipulating Array data structure

EQUIPMENT:
• Computer equipped with Microsoft Visual Studio 15 and Office 16

BACKGROUND:

In computer science, an array data structure, or simply an array, is a data


structure consisting of a collection of elements (values or variables), each identified by at least
one array index or key. An array is stored such that the position of each element can be
computed from its index tuple by a mathematical formula. The simplest type of data structure
is a linear array, also called one-dimensional array. For example, an array of 10 32-bit integer
variables, with indices 0 through 9, may be stored as 10 words at memory addresses 2000,
2004, 2008, ... 2036, so that the element with index i has the address 2000 + 4 × i. The memory
address of the first element of an array is called first address, foundation address, or base
address.

Arrays are among the oldest and most important data structures, and are used by almost every
program. They are also used to implement many other data structures, such as lists and strings.
They effectively exploit the addressing logic of computers. In most modern computers and
many external storage devices, the memory is a one-dimensional array of words, whose indices
are their addresses. Arrays are useful mostly because the element indices can be computed
at run time. Among other things, this feature allows a single iterative statement to process
arbitrarily many elements of an array. For that reason, the elements of an array data structure
are required to have the same size and should use the same data representation.

Figure 1
Lab Manual of ‘Data Structures and Algorithms’

LAB TASKS:

Problem 1:

Create two arrays of length 6


• Input their values from user
• Swap their values as follow using loops:

55 23 14 88 25 88

24 44 48 36 94 14

• Display arrays after swapping.

Problem 2:

Create an integer array of length 20


• Input value from user
• Calculate and display second maximum and second minimum values of that array.
For example:
If array = {22,55,14,36,15,84….}, then
Second maximum = 55
Second minimum = 15

Problem 3:

Implement a function that finds common elements in two arrays. You can assume that the sets
are stored using arrays. So, if array1 = {1,2,3,4,5,6,3,2} and array2 is {1,3,5,7}, then array3
should be {1,3,5}. Note array3 should not have any duplicate elements. You have to:
• Display the count of repeating elements (for example 1 repeats 1 time, 3 repeats 2 time)
• Think of all the functions that are required for this problem. Each function should
perform its dedicated task. So plan them out before implementing them.
• Main should only have a set of function calls

Problem 4:

Write a code to take input in 2 dynamic arrays, ask the size of arrays from user. After you have
finished taking input for one dynamic array start for the second. The size of arrays may be
different. Now completely swap the contents of the two dynamic arrays.
Lab Manual of ‘Data Structures and Algorithms’

Problem 5:

Create an array of length 6


• Input values from user
• Input a number N from user (for which ternion has to be calculated)
• Find and display the ternion/triplet of sum in the array

(Note: Ternion/triplet is a set or combination of 3 values)


For Example:
Array = {1, 14, 9, 11, 2, 48}, N = 14
Ternion/Triplet = {1, 11, 2}
Lab Manual of ‘Data Structures and Algorithms’

CL210 – Data Structures and Algorithms Lab


The focus of this lab is to cover some of the commonly used data structures and algorithms in
software development. It is aimed at helping the students to understand the reasons for
choosing certain structures or algorithms while implementing them using Microsoft Visual
Studio.
CLO Statement ↓ Exemplary Proficient Developing Beginning Novice
Score → (5) (4) (3) (2) (1)

Demonstrate
Attempts Attempts Understand
elementary Attempts all
1 partial lab lab tasks the given
skills to lab tasks No
tasks with with concept but
construct with correct attempt
correct incorrect unable to
various data output
output output apply it
structures.

Behaves Completes
Completes
responsibly, the lab task
Completes the lab task Poorly
3 and with help of Does not
the lab task with minor attempts
individually instructor work
on his own help of lab tasks
performs the and students
instructor
lab. around

CLO MARKS OBTAINED


1
3

Instructor’s Signature: __________________________

You might also like