Sunteți pe pagina 1din 9

Page 1 of 9

UNIT 2: DATA STRUCTURES


CHAPTER 1: ARRAYS
SINGLE DIMENSION ARRAY
1.

Write the definition of a function Change (int P [ ], int N) in C++, which should change all
the multiples of 10 in the array to 10 and rest of the elements as 1. For example, if an array
of 10 integers is as follows :

[2]

[2015]

[3]

[2014]

[3]

[2013]

[3]

[2012]

After executing the function, the array content should be changed as follows : P[0]

2.

Write code for a function void EvenOdd ( int T[ ], int C ) in C++, to add 1 in all the odd
values and 2 in all the even values of the array T.
Example : If the original content of the array T is

The modified content will be :

3.

Write the definition for a function void Transfer (int A [6], int B [6] ) in C++, which takes
two integer arrays, each containing 6 elements as parameters. The function should
exchange all odd places (1st, 3rd and 5th ) of the two arrays, for example
If the array A contains
and if the array B contains
Then the function should make the contents of the array A as
And the contents of array B as

4.

Write a function SWAP2BEST (int ARR [ ], int Size) in C++ to modify the content of the
array in such a way that the elements, which are multiples of 10 swap with the value

Page 2 of 9

present in the very next position in the array.


For example :
If the content of array ARR is
90, 56, 45, 20, 34, 54
The content of array ARR should become
56, 90, 45, 34, 20, 54
5.

Write a Get1From2 ( ) function in C++ to transfer the content from two arrays FIRST [ ]
and SECOND [ ] to array ALL [ ]. The even places (0, 2, 4 ...) of array ALL [ ] should get
the content from the array FIRST [ ] and odd places (1, 3, 5,) of the array ALL [ ] should
get the content from the array SECOND [ ].
Example:
If the FIRST [ ] array contains
30, 60, 90
And the SECOND[ ] array contains
10, 50, 80
The ALL [ ] array should contain
30, 10, 60, 50, 90, 80

[3]

[2011]

6.

Write a function CHANGE( ) in C++, which accepts an array of integer and its size as
parameters and divide all those array elements by 7 which are divisible by 7 and multiply
other-array elements by 3.
Sample Input Data of the array

[3]

[2010]

Content of the array after Calling CHANGE() function

7.

Given two arrays A and B. Array A contains all the elements of B but one more element
extra. Write a c++ function which accepts array A and B and its size as arguments /
parameters and find out the extra element in Array A. (Restriction: array elements are not
in order)
Example:
If Array A is {14, 21, 5, 19, 8, 4, 23, 11}
and Array B is {23, 8, 19, 4, 14, 11, 5 }
Then output will be 5 (extra element in Array A)

[3]

[2009]

8.

Write a function in C++ which accepts a integer array and its size as an arguments and
prints the output (using nested loops) in following format :
Example : if the array is having
12459

[4]

[2008]

Page 3 of 9

Then the output should be


1
22
4444
55555
999999
9.

Write a function in C++ which accepts an integer array and its size.as arguments and [4]
replaces elements having even values with its half and elements having odd values with
twice its value.
Example : if an array of five elements initially contains the elements as
3, 4, 5, 16, 9
then the function should rearrange the content of the array as
6, 2, 10, 8, 18

[2007]

10.

Write a function in C++ which accepts an integer array and its size as arguments / [4]
parameters and then assigns the elements into a two dimensional array of integers in the
following format:
If the array is 1, 2, 3, 4, 5, 6
The resultant 2 D array is given below
0
0
0
0
0
1
0
0
0
0
2
1
0
0
0
3
2
1
0
0
4
3
2
1
0
5
4
3
2
1
6
5
4
3
2
1
If the array is 1, 2, 3
The resultant 2 D array is given below
0
0
1
0
2
1
3
2
1

[2006]

11.

Write a function bubble sort to sort the passed array of 10 integers in descending order
using bubble sort.
TWO DIMENSIONAL ARRAY

[2]

[2006]

1.

Write a function REVROW (int P [ ] [5], int N, int M) in C++ to display the content of a
two dimensional array, with each row content in reverse order.
For example, if the content of array is as follows :
1
1
5
4
5
5
2
6
5
1
1
9
9
8
6
3
1
2
7
3
2
6
4
8
11
3
1
6
1

[3]

[2015]

Page 4 of 9

The function should display output as:


5
4
1
5
6
8
3
7
8
4
1
6

5
6
9
2
6
1

1
2
9
1
2
3

1
5
1
3
8
1

2.

Write a user-defined function AddEnd2 (int A [ ] [4], int N, int M) in C++ to find and
display the sum of all the values, which are ending with 2 (i.e., units place is 2).
For example if the content of array is :
22 16 12
19 5 2
The output should be 36.

[2]

[2014]

3.

Write a user-defined function int SumSingle ( int A [4] [4] ) in C++, which finds and [2]
returns the sum of all numbers present in the first row of the array, for example, if the array
contains

[2013]

Then the function should return 33.


4.

Write a function ALTERNATE ( int A [ ] [ 3 ], int N, int M ) in C++ to display all alternate
elements from two-dimensional array A (starting from A [ 0 ] [ 0 ] ).
For example : If the array is containing :
23 54 76
37 19 28
62 13 19
The output will be
23 76 19 62 19

[2]

[2012]

5.

Write a COLSUM ( ) function in C++ to find sum of each column of a N x M Matrix.

[2]

[2011]

6.

Write a function int SKIPSUM (int A [ ] [3], int N,int M) in C++ to find and return the sum
of elements from all alternate elements of a two-dimensional array starting from A[0][0].
Hint:
If the following is the content of the array

[2]

[2010]

Page 5 of 9

The function SKIPSUM() should add elements A[0][0], A[0][2], A[1][l],


A[2][0] and A[2][2].

25.

Write a function in C++ which accepts an integer array and its size as arguments / [3]
parameters and assigns the elements into a two dimensional array of integers in the
following format.
if the array is 9,8,7,6,5,4 The resultant 2D array is given below

[2009]

if the array is 1, 2, 3
The resultant 2D array is given below

31.

Write a function in C++ which accepts a 2D array of integers and its size as arguments and
displays the elements of middle row and the elements of middle column.
[Assuming the 2D Array to be a square matrix with odd dimension i.e. 33, 55, 77 etc...]
Example, if the array content is
354
769
218
Output through the function should be :
Middle Row : 7 6 9
Middle Column : 5 6 1

[2]

[2007]

MEMORY ADDRESS CALCULATION


2.

A two dimensional array ARR [50] [20] is stored in the memory along the row with each of
its elements occupying 4 bytes. Find the address of the element ARR [30] [10], if the
element ARR [10] [5] is stored at the memory location 15000.

[3]

[2015]

6.

An array A[20][30] is stored along the row in the memory with each element requiring 4
bytes of storage. If the base address of array A is 32000, find out the location of A[15][10].

[3]

[2014]

Page 6 of 9

Also, find the total number of elements present in this array.


10.

An array S [10] [15] is stored in the memory with each element requiring 2 bytes of [3]
storage. If the base address of array S is 25000, determine the location of S [5] [10] if the
array S is stored along the column.

[2013]

14.

An array T [20] [10] is stored in the memory along the column with each of the elements
occupying 2 bytes. Find out the memory the memory location of T [10] [5], if the element
T [2] [9] is stored at the location 7600.

[3]

[2012]

18.

An array P[20] [50] is stored in the memory along the column with each of its
element occupying 4 bytes, find out the 1ocation of P[15][10], if P[0][0] is
stored at 5200.

[2]

[2011]

22.

An array P[50][60] is stored in the memory along the column with each of the
element occupying 2 bytes, find out the memory location for the element P[10]
[20], if the Base Address of the array is 6800.

[3]

[2010]

26.

Each element of an array DATA[10][10] requires 8 bytes of storage. If base address of


array DATA is 2000, determine the location of DATA[4][5], when array is stored
(i)
Row-wise.
(ii)
Column-wise

[4]

[2009]

[3]

[2008]

28.
An array A[10][20] is stored in the memory with each element occupying 2 bytes of
storage. If the Base address of array in the memory is 800 , determine the location of A[9]
[10] when the array is stored as (i) Row Major (ii) column major.

30.

An array Arr[15][20] is stored in the memory along the row with each element
occupying 4 bytes. Find out the Base Address and address of the element Arr[3][2],
if the element Arr[5][2] is stored at the address 1500.

[4]

[2007]

33.

An array MAT [15] [7] is stored in the memory along the column with each element [4]
occupying 2 bytes of memory. Find out the base address and the address of element MAT
[2] [5], if the location of MAT [5] [4] is stored at the address 100.

[2006]

CHAPTER 2: STACK
1.

Write the definition of a member function PUSH( ) in C++, to add a new book in a
dynamic stack of BOOKS considering the following code is already included in the
program :
struct BOOKS
{ char ISBN[20], TITLE[80];
BOOKS *Link;
};

[4]

[2015]

Page 7 of 9

class STACK
{ BOOKS *Top;
public:
STACK(){Top=NULL;}
void PUSH();
void POP();
~STACK();
};
2.

Convert the following Infix expression to its equivalent Postfix expression, showing the [2]
stack contents for each step of conversion : U * V + R / ( S T )

[2015]

3.

Evaluate the following postfix expression. Show the status of stack after execution of each [2]
operation separately : T, F, NOT, AND, T, OR, F, AND

[2014]

4.

Write a function PUSHBOOK ( ) in C++ to perform insert operation on a Dynamic Stack,


which contains Book_no and Book_Title. Consider the following definition of NODE,
while writing your C++ code.
struct NODE
{ int Book_No;
char Book_Title[20];
NODE *Next;
};

[4]

[2014]

5.

Evaluate the following postfix expression using a stack and show the contents of stack
after execution of each operation: 5, 3, 2, *, 4, 2, /, -, *

[2]

[2013]

6.

Write a function in C++ to perform Insert operation in a static circular Queue containing
Books information (represented with the help of an array of structure BOOK).
struct BOOK
{ long Accno;
// Book Accession Number
Char Title [20]; // Book Title
};

[4]

[2012]

7.

Evaluate the following POSTFIX notation. Show status of Stack after every step of
evaluation (i.e. after each operator): True, False, NOT, AND, False, True, OR, AND

[2]

[2012]

8.

Evaluate the following postfix notation of expression:

[2]

[2011]

9.

Write a complete program in C++ to implement dynamically allocated Stack containing


names of Countries.

[4]

[2010]

[2]

[2010]

50, 60, + , 20, 10, -, *

10. Evaluate the following postfix notation of expression: (Show status of Stack after each
operation) False, True, NOT, OR, True, False, AND, OR

Page 8 of 9

11.

Write the function to perform push and pop operation on a dynamically allocated stack of
customers implemented with the help of the following structure:
struct employee
{ int eno;
char ename[20];
employee *link;
};

[4]

[2009]

12. Evaluate the following postfix notation of expression: 5, 11, , 6, 8, +, 12, *, /

[2]

[2009]

13. Consider the following portion of a program , which implements a linked stack for
Library. Write the definition of function PUSH(),to insert a new node in the stack with
required information.
struct Library
{
int id;
char names[20];
};
class stack
{
Library *top;
public :
stack() {
top=NULL; }
void PUSH();
void POP();
};

[3]

[2008]

14.

[2]

[2008]

15. Evaluate the following postfix notation of expression :


15 3 2 + / 7 + 2 *

[2]

[2007]

16. Evaluate the following postfix expression using a stack and show the contents of the stack
after execution of each operation. 5, 10, *, 20, 2, /, +

[2]

[2006]

Convert the following infix expression into postfix. show the stack status after execution
of each operation: TRUE OR FALSE AND NOT FALSE OR FALSE

CHAPTER 3: QUEUE
1. Give the necessary declaration of linked implemented Queue containing players information
(as defined in the following definition of Node). Also write a user defined function in C++ to
delete one Players information from the Queue.
struct Node
{
int PlayerNo;
char PlayerName[20];

[4] [2013]

Page 9 of 9

Node *Link;
}
2. Write a function in C++ to perform Insert: operation on a dynamically allocated Queue [4] [2011]
containing Passenger details as given in the following definition of NODE.
struct NODE
{ long Pno;
//passenger Number
char Pname[20] ; //passenger Name
NODE *Link.;
};
3. Write a function in C++ to delete a node containing names of student , from a dynamically [3] [2008]
allocated Queue of names implemented with the help of following structure :
struct student
{
char name[20];
student *next;
} *front , *rear;
4. Write a function in C++ to delete a node containing customers information, from a
dynamically allocated Queue of Customers implemented with the help of the following
structure :
struct Customer
{ int CNo;
char CName[20];
Customer *Link;
};

[4] [2007]

5. What is circular queue? How is it different from simple queue? Write a function in C++ to
perform Delete operation in dynamically allocated Queue containing names of students.

[4] [2006]

S-ar putea să vă placă și