-
Notifications
You must be signed in to change notification settings - Fork 0
/
23_WavePrint.cpp
76 lines (66 loc) · 1.49 KB
/
23_WavePrint.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <iostream>
#include <vector>
using namespace std;
vector<int> wavePrint(vector<vector<int>>matrix, int nrows, int ncols)
{
vector<int> ans;
for (int col = 0; col < ncols; col++)
{
// Odd index cols.
// Bottom to top.
if (col&1)
{
for (int row = nrows-1; row >= 0; row--)
{
cout << matrix[row][col] << " ";
// ans.push_back(matrix[row][col]);
}
cout << endl;
}
// Even Index column
//top to bottom
else
{
for (int row = 0; row < nrows; row++)
{
cout << matrix[row][col] << " ";
// ans.push_back(matrix[row][col]);
}
cout << endl;
}
}
}
void printMatrix(vector<vector<int>> matrix, int rows, int cols)
{
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
cout << matrix[j][i] << " ";
}
cout << endl;
}
}
int main()
{
vector<vector<int>> matrix;
// Input:
// cout<<(3&1);
cout << "enter elements of matrix:";
for (int i = 0; i < 3; i++)
{
vector<int> temp;
for (int j = 0; j < 3; j++)
{
int x;
cin>>x;
temp.push_back(x);
}
matrix.push_back(temp);
}
printMatrix(matrix, 3,3);
cout<<"Wave Print"<<endl;
wavePrint(matrix, 3, 3);
// printMatrix(matrix, 3,4);
return 0;
}