-->

Data Structure

Question
CBSEENCO12011722

Write a function ALTERNATE (int A[][3],int N,int M) in C++ to display all alternate element 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

Solution
#include <iostream.h> 
#include <conio.h>
void process_Array(int Arr[][3],int x, int y); 
void process_Array(int A[][3],int N, int M)
{
	clrscr();
	for (int R = 0; R < N; R++)
	{
		if(R%2==0)
		{
			for (int C = 0; C < M; C=C+2)
			{
				cout<< A[R][C]<<' ';
			}
		}
		else
		{
			for (int C = 1; C < M;C=C+2)
			{
				cout<< A[R][C]<<' ';
			}
		}
	}
	cout<<endl; 
	cout<<endl;
	for (int I = 0; I < N; I++)
	{
		for (int J = 0; J < M; J++)
		{
			cout << A[I][J]<<' ';
		}
		cout<<endl;
	}
}
int main ()
{
	int arr[3][3] ={{23, 54, 76},
	{37, 19, 28},
	{62, 13, 19},
};
process_Array(arr,3,3); 
return 0;
}

Some More Questions From Data Structure Chapter

T[20][50] is a two dimensional array, which is stored in the memory along the row with each of its element occupying 4 bytes, find the address of the element T[15][5], if the element T[10][8] is stored at the memory location 52000.

Write the definition of a member function INSERT() for a class QUEUE in C++, to insert an ITEM in a dynamically allocated Queue of items considering the following code is already written as a part of the program.

struct ITEM
{
	int INO; char INAME[20];
	ITEM *Link;
};
class QUEUE
{
	ITEM *R,*F;
	public :
	QUEUE() {R=NULL;F=NULL;}
	void INSERT();
	void DELETE();
	~QUEUE();
};

Write a definition for a function SHOWMID (int P[][5], int R, int C) in C++ to display the elements of the middle row and middle column from a two-dimensional array P having R number of rows and C number of columns. For example, if the content of the array is as follows:

115 112 116 101 125
103 101 121 102 101
185 109 109 160 172

The function should display the following as output :
103 101 121 102 101
116 121 109

 

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

Write the definition of a member function Pop() in C++, to delete a book from a dynamic stack of TEXTBOOKS considering the following code is already included in the program.

struct TEXTBOOKS
{
	char ISBN[20]; char TITLE[80];
	TEXTBOOKS *Link;
};
class STACK
{
	TEXTBOOKS *Top;
public:
	STACK(){Top=NULL;}
	void Push();
	void Pop();
	~STACK();
};

Write a function REVCOL (int P[] [5], int N, int M) in C++ to display the content of a two-dimensional array, with each column content in reverse order.

Note: Array may contain any number of rows.

For example, if the content of the array is as follows:

15 12 56 45 51
13 91 92 87 63
11 23 61 46 81

The function should display output as:

11 23 61 46 81
13 91 92 87 63
15 12 56 45 51

 

Write a function ALTERNATE (int A[][3],int N,int M) in C++ to display all alternate element 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