Data Structure
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 |
void REVCOL(int P[][5],int N,int M)
{
for(int I=0;I<N/2;I++)
{
for(int J=0;J<M;J++)
{
int T = P[I][J];
P[I][J] = P[NI1][J];
P[NI1][J] = T;
}
}
for(I=0;I<N;I++)
{
for(int J=0;J<M;J++)
cout<<P[I][J];
cout<<endl;
}
}â
Sponsor Area
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 |
Sponsor Area
Sponsor Area