Anticlockwise spiral view of diamond element in matrix

Anticlockwise spiral view of matrix

Here given code implementation process.

/*
  C Program 
+ Anticlockwise spiral view of diamond element in matrix
*/
#include<stdio.h>
#define ROW 5
#define COL 5

// Method which is displaying the Anticlockwise spiral 
// Of matrix in diamond(mid) element
void spiral_view(int matrix[ROW][COL],
  int s_row,
  int s_col,
  int e_row,
  int e_col,
 
  int k)
{
  //Find the middle column
  int mid_col = s_col + ((e_col - s_col)/2);

  //Get middle row (valid for odd square matrix)
  int mid_row = mid_col;
  
  // Matrix are divided into 4 section

  // Starting of middle row and column in form of top
  // Top to Left-bottom
  for (int i = mid_col,j=0; i > s_col && k > 0 ; i--,k--,j++)
  {
    printf("%4d",matrix[s_row+j][i] );
  }

  // Middle left to middle right bottom
  for (int i = s_col,j=0; i <= mid_col && k > 0 ; i++,k--,j++)
  {
    printf("%4d",matrix[(mid_row)+j][i] );
  }
  // Middle bottom to middle right side 
  for (int i = mid_col+1,j=1; i <= e_col && k > 0 ; i++,k--,j++)
  {
    printf("%4d",matrix[(e_row)-j][i] );
  }
  // Middle right side to  top middle 
  for (int i = e_col-1,j=1; i > mid_col && k > 0 ; i--,k--,j++)
  {
    printf("%4d",matrix[(mid_row)-j][i] );
  }


  
  if(s_row+1 <= e_row-1 && k > 0)
  {
    //Recursive call
    spiral_view(matrix,s_row+1,s_col+1,e_row-1,e_col-1,k);
  }
  
    
}
void diamond_spiral(int matrix[ROW][COL])
{
  //Check whether the given matrix is ​​a valid odd shape or not
  if(ROW != COL || COL%2 == 0)
  {
    //When Yes not a valid size
    printf("\nNot a valid perfect Odd square matrix");
    return;
  }
  //(ROW*COL)-((COL+1)/2)*4 are provide the value of number of diamond element
  spiral_view(matrix,0,0,ROW-1,COL-1,(ROW*COL)-((COL+1)/2)*4);

}
int main(){
  //Matrix element
  int matrix[ROW][COL] ={
    {1,  2,  3,  4,  5},
    {6,  7,  8,  9,  10},
    {11, 12, -1, 15,  16},
    {17, 18, 19, 20,  21},
    {22, 23, 24, 25,  26}

  }; 
  diamond_spiral(matrix);



  return 0;
}

Output

   3   7  11  18  24  20  16   9   8  12  19  15  -1
/*
  C++ Program 
+ Anticlockwise spiral view of diamond element in matrix
*/
#include<iostream>

using namespace std;

#define ROW 5
#define COL 5
class MyMatrix {
	public:

		// Method which is displaying the Anticlockwise spiral 
		// Of matrix in diamond(mid) element
		void spiral_view(int matrix[ROW][COL], int s_row, int s_col, int e_row, int e_col, int k) {
			//Find the middle column
			int mid_col = s_col + ((e_col - s_col) / 2);
			//Get middle row (valid for odd square matrix)
			int mid_row = mid_col;
			// Matrix are divided into 4 section
			// Starting of middle row and column in form of top
			// Top to Left-bottom

			for (int i = mid_col, j = 0; i > s_col && k > 0; i--, k--, j++) {
				cout << " " << matrix[s_row + j][i];
			}
			// Middle left to middle right bottom

			for (int i = s_col, j = 0; i <= mid_col && k > 0; i++, k--, j++) {
				cout << " " << matrix[mid_row + j][i];
			}
			// Middle bottom to middle right side 

			for (int i = mid_col + 1, j = 1; i <= e_col && k > 0; i++, k--, j++) {
				cout << " " << matrix[e_row - j][i];
			}
			// Middle right side to  top middle 

			for (int i = e_col - 1, j = 1; i > mid_col && k > 0; i--, k--, j++) {
				cout << " " << matrix[mid_row - j][i];
			}
			if (s_row + 1 <= e_row - 1 && k > 0) {
				//Recursive call
				this->spiral_view(matrix, s_row + 1, s_col + 1, e_row - 1, e_col - 1, k);
			}
		}
	void diamond_spiral(int matrix[ROW][COL]) {
		int row = ROW;
		int col = COL;
		//Check whether the given matrix is ​​a valid odd shape or not

		if (row != col || col % 2 == 0) {
			//When Yes not a valid size

			cout << "\nNot a valid perfect Odd square matrix";
			return;
		}
		//(row*col)-((col+1)/2)*4 are provide the value of number of 
		// diamond element
		this->spiral_view(matrix, 0, 0, row - 1, col - 1, (row *col) - ((col + 1) / 2) *4);
	}
};
int main() {
	MyMatrix obj ;
	int matrix[ROW][COL] = {
			{
				1,
				2,
				3,
				4,
				5
			},
			{
				6,
				7,
				8,
				9,
				10
			},
			{
				11,
				12,
				-1,
				15,
				16
			},
			{
				17,
				18,
				19,
				20,
				21
			},
			{
				22,
				23,
				24,
				25,
				26
			}
		};
	obj.diamond_spiral(matrix);
	return 0;
}

Output

 3 7 11 18 24 20 16 9 8 12 19 15 -1
/*
  Java Program
  Anticlockwise spiral view of diamond element in matrix
*/
public class MyMatrix {
 
  // Method which is displaying the Anticlockwise spiral 
  // Of matrix in diamond(mid) element
  void spiral_view(int [][]matrix,
    int s_row,
    int s_col,
    int e_row,
    int e_col,
   
    int k)
  {
    //Find the middle column
    int mid_col = s_col + ((e_col - s_col)/2);

    //Get middle row (valid for odd square matrix)
    int mid_row = mid_col;
    
    // Matrix are divided into 4 section

    // Starting of middle row and column in form of top
    // Top to Left-bottom
    for (int i = mid_col,j=0; i > s_col && k > 0 ; i--,k--,j++)
    {
      System.out.print("  "+matrix[s_row+j][i] );
    }

    // Middle left to middle right bottom
    for (int i = s_col,j=0; i <= mid_col && k > 0 ; i++,k--,j++)
    {
      System.out.print("  "+matrix[(mid_row)+j][i] );
    }
    // Middle bottom to middle right side 
    for (int i = mid_col+1,j=1; i <= e_col && k > 0 ; i++,k--,j++)
    {
      System.out.print("  "+matrix[(e_row)-j][i] );
    }
    // Middle right side to  top middle 
    for (int i = e_col-1,j=1; i > mid_col && k > 0 ; i--,k--,j++)
    {
      System.out.print("  "+matrix[(mid_row)-j][i] );
    }


    
    if(s_row+1 <= e_row-1 && k > 0)
    {
      //Recursive call
      spiral_view(matrix,s_row+1,s_col+1,e_row-1,e_col-1,k);
    }
    
      
  }
  void diamond_spiral(int [][]matrix)
  {
    int row = matrix.length;
    int col = matrix[0].length;
    //Check whether the given matrix is ​​a valid odd shape or not
    if(row != col || col%2 == 0)
    {
      //When Yes not a valid size
      System.out.print("\nNot a valid perfect Odd square matrix");
      return;
    }
    //(row*col)-((col+1)/2)*4 are provide the value of number of 
    // diamond element
    spiral_view(matrix,0,0,row-1,col-1,(row*col)-((col+1)/2)*4);

  }

  public static void main(String[] args) {

    MyMatrix obj = new MyMatrix();
    //Define matrix 
    int [][]matrix ={
      {1,  2,  3,  4,  5},
      {6,  7,  8,  9,  10},
      {11, 12, -1, 15,  16},
      {17, 18, 19, 20,  21},
      {22, 23, 24, 25,  26}

    }; 
    obj.diamond_spiral(matrix);

  }
}

Output

 3 7 11 18 24 20 16 9 8 12 19 15 -1
/*
  C# Program
  Anticlockwise spiral view of diamond element in matrix
*/
using System;
public class MyMatrix {

	// Method which is displaying the Anticlockwise spiral 
	// Of matrix in diamond(mid) element
	void spiral_view(int[,] matrix,
		int s_row,
		int s_col,
		int e_row,
		int e_col,

		int k) {
		//Find the middle column
		int mid_col = s_col + ((e_col - s_col) / 2);

		//Get middle row (valid for odd square matrix)
		int mid_row = mid_col;

		// Matrix are divided into 4 section

		// Starting of middle row and column in form of top
		// Top to Left-bottom
		for (int i = mid_col, j = 0; i > s_col && k > 0; i--, k--, j++) {
			Console.Write("  " + matrix[s_row + j,i]);
		}

		// Middle left to middle right bottom
		for (int i = s_col, j = 0; i <= mid_col && k > 0; i++, k--, j++) {
			Console.Write("  " + matrix[(mid_row) + j,i]);
		}
		// Middle bottom to middle right side 
		for (int i = mid_col + 1, j = 1; i <= e_col && k > 0; i++, k--, j++) {
			Console.Write("  " + matrix[(e_row) - j,i]);
		}
		// Middle right side to  top middle 
		for (int i = e_col - 1, j = 1; i > mid_col && k > 0; i--, k--, j++) {
			Console.Write("  " + matrix[(mid_row) - j,i]);
		}



		if (s_row + 1 <= e_row - 1 && k > 0) {
			//Recursive call
			spiral_view(matrix, s_row + 1, s_col + 1, e_row - 1, e_col - 1, k);
		}


	}
	void diamond_spiral(int[,] matrix) {
		int row = matrix.GetLength(0);
		int col = matrix.GetLength(1);
		//Check whether the given matrix is ​​a valid odd shape or not
		if (row != col || col % 2 == 0) {
			//When Yes not a valid size
			Console.Write("\nNot a valid perfect Odd square matrix");
			return;
		}
		//(row*col)-((col+1)/2)*4 are provide the value of number of 
		// diamond element
		spiral_view(matrix, 0, 0, row - 1, col - 1, (row * col) - ((col + 1) / 2) * 4);

	}

	public static void Main(String[] args) {

		MyMatrix obj = new MyMatrix();
		//Define matrix 
		int[,] matrix = {
			{
				1,
				2,
				3,
				4,
				5
			},
			{
				6,
				7,
				8,
				9,
				10
			},
			{
				11,
				12,
				-1,
				15,
				16
			},
			{
				17,
				18,
				19,
				20,
				21
			},
			{
				22,
				23,
				24,
				25,
				26
			}

		};
		obj.diamond_spiral(matrix);

	}
}

Output

  3  7  11  18  24  20  16  9  8  12  19  15  -1
# Python 3 Program
# Anticlockwise spiral view of diamond element in matrix
class MyMatrix :
  def spiral_view(self, matrix, s_row, s_col, e_row, e_col, k) :
    mid_col = s_col + int((e_col - s_col) / 2)
    mid_row = mid_col
    #  Top to Left-bottom
    #  Starting of middle row and column in form of top
    i = mid_col
    j = 0
    while (i > s_col and k > 0) :
      print(" ", matrix[s_row + j][i],end="")
      i -= 1
      k -= 1
      j += 1
    
    #  Middle left to middle right bottom
    i = s_col
    j = 0
    while (i <= mid_col and k > 0) :
      print(" ", matrix[(mid_row) + j][i],end="")
      i += 1
      k -= 1
      j += 1
    
    #  Middle bottom to middle right side 
    i = mid_col + 1
    j = 1
    while (i <= e_col and k > 0) :
      print(" ", matrix[(e_row) - j][i],end="")
      i += 1
      k -= 1
      j += 1
    
    #  Middle right side to  top middle 
    i = e_col - 1
    j = 1
    while (i > mid_col and k > 0) :
      print(" ", matrix[(mid_row) - j][i],end="")
      i -= 1
      k -= 1
      j += 1
    
    if (s_row + 1 <= e_row - 1 and k > 0) :
      self.spiral_view(matrix, s_row + 1, s_col + 1, e_row - 1, e_col - 1, k)
    
  
  def diamond_spiral(self, matrix) :
    row = len(matrix)
    col = len(matrix[0])
    # Check whether the given matrix is a valid odd shape or not

    if (row != col or col % 2 == 0) :
      print("\nNot a valid perfect Odd square matrix")
      return
    
    self.spiral_view(matrix, 0, 0, row - 1, col - 1, (row * col) - int((col + 1) / 2) * 4)
  

def main() :
  obj = MyMatrix()
  # Define matrix 
  matrix = [
    [1, 2, 3, 4, 5],
    [6, 7, 8, 9, 10],
    [11, 12, -1, 15, 16],
    [17, 18, 19, 20, 21],
    [22, 23, 24, 25, 26]
  ]
  obj.diamond_spiral(matrix)


if __name__ == "__main__":
  main()

Output

 3  7  11  18  24  20  16  9  8  12  19  15  -1
# Ruby Program 
# Anticlockwise spiral view of diamond element in matrix
class MyMatrix 
	def spiral_view(matrix, s_row, s_col, e_row, e_col, k) 
		mid_col = s_col + ((e_col - s_col) / 2)
		mid_row = mid_col
		#  Top to Left-bottom
		#  Starting of middle row and column in form of top
		i = mid_col
		j = 0
		while (i > s_col and k > 0) 
			print(" ", matrix[s_row + j][i])
			i -= 1
			k -= 1
			j += 1
		end
		#  Middle left to middle right bottom
		i = s_col
		j = 0
		while (i <= mid_col and k > 0) 
			print(" ", matrix[(mid_row) + j][i])
			i += 1
			k -= 1
			j += 1
		end
		#  Middle bottom to middle right side 
		i = mid_col + 1
		j = 1
		while (i <= e_col and k > 0) 
			print(" ", matrix[(e_row) - j][i])
			i += 1
			k -= 1
			j += 1
		end
		#  Middle right side to  top middle 
		i = e_col - 1
		j = 1
		while (i > mid_col and k > 0) 
			print(" ", matrix[(mid_row) - j][i])
			i -= 1
			k -= 1
			j += 1
		end
		if (s_row + 1 <= e_row - 1 and k > 0) 
			self.spiral_view(matrix, s_row + 1, s_col + 1, e_row - 1, e_col - 1, k)
		end
	end
	def diamond_spiral(matrix) 
		row = matrix.length
		col = matrix[0].length
		# Check whether the given matrix is a valid odd shape or not

		if (row != col or col % 2 == 0) 
			print("\nNot a valid perfect Odd square matrix")
			return
		end
		self.spiral_view(matrix, 0, 0, row - 1, col - 1, (row * col) - ((col + 1) / 2) * 4)
	end
end
def main() 
	obj = MyMatrix.new()
	# Define matrix 
	matrix = [
		[1, 2, 3, 4, 5],
		[6, 7, 8, 9, 10],
		[11, 12, -1, 15, 16],
		[17, 18, 19, 20, 21],
		[22, 23, 24, 25, 26]
	]
	obj.diamond_spiral(matrix)
end
main()

Output

 3 7 11 18 24 20 16 9 8 12 19 15 -1
/*
 Scala Program
 Anticlockwise spiral view of diamond element in matrix
*/
class MyMatrix {
	def spiral_view(matrix: Array[Array[Int]], s_row: Int, s_col: Int, e_row: Int, e_col: Int, size: Int): Unit = {
		var mid_col: Int = s_col + ((e_col - s_col) / 2).toInt;
		var mid_row: Int = mid_col;
		var k: Int = size;
		// Top to Left-bottom
		// Starting of middle row and column in form of top
		var i: Int = mid_col;
		var j: Int = 0;
		while (i > s_col && k > 0) {
			print(" " + matrix(s_row + j)(i));
			i -= 1;
			k -= 1;
			j += 1;
		}
		// Middle left to middle right bottom
		i = s_col;j = 0;
		while (i <= mid_col && k > 0) {
			print(" " + matrix((mid_row) + j)(i));
			i += 1;
			k -= 1;
			j += 1;
		}
		// Middle bottom to middle right side 
		i = mid_col + 1;j = 1;
		while (i <= e_col && k > 0) {
			print(" " + matrix((e_row) - j)(i));
			i += 1;
			k -= 1;
			j += 1;
		}
		// Middle right side to  top middle 
		i = e_col - 1;j = 1;
		while (i > mid_col && k > 0) {
			print(" " + matrix((mid_row) - j)(i));
			i -= 1;
			k -= 1;
			j += 1;
		}
		if (s_row + 1 <= e_row - 1 && k > 0) {
			this.spiral_view(matrix, s_row + 1, s_col + 1, e_row - 1, e_col - 1, k);
		}
	}
	def diamond_spiral(matrix: Array[Array[Int]]): Unit = {
		val row: Int = matrix.length;
		val col: Int = matrix(0).length;
		//Check whether the given matrix is a valid odd shape or not

		if (row != col || col % 2 == 0) {
			print("\nNot a valid perfect Odd square matrix");
			return;
		}
		this.spiral_view(matrix, 0, 0, row - 1, col - 1, (row * col) - ((col + 1) / 2).toInt * 4);
	}
}
object Main {
	def main(args: Array[String]): Unit = {
		val obj: MyMatrix = new MyMatrix();
		//Define matrix 
		val matrix: Array[Array[Int]] = Array(
			Array(1, 2, 3, 4, 5),
			Array(6, 7, 8, 9, 10),
			Array(11, 12, -1, 15, 16),
			Array(17, 18, 19, 20, 21),
			Array(22, 23, 24, 25, 26));obj.diamond_spiral(matrix);
	}
}

Output

 3 7 11 18 24 20 16 9 8 12 19 15 -1
/*
  Swift 4 Program
  Anticlockwise spiral view of diamond element in matrix
*/
class MyMatrix {
	func spiral_view(_ matrix: [[Int]], _ s_row: Int, _ s_col: Int, _ e_row: Int, _ e_col: Int, _ size: Int) {
		let mid_col: Int = s_col + ((e_col - s_col) / 2);
		let mid_row: Int = mid_col;
        var k: Int = size;
		// Top to Left-bottom
		// Starting of middle row and column in form of top
		var i: Int = mid_col;
		var j: Int = 0;
		while (i > s_col && k > 0) {
			print(" ", matrix[s_row + j][i],terminator:"");
			i -= 1;
			k -= 1;
			j += 1;
		}
		// Middle left to middle right bottom
		i = s_col;
		j = 0;
		while (i <= mid_col && k > 0) {
			print(" ", matrix[(mid_row) + j][i],terminator:"");
			i += 1;
			k -= 1;
			j += 1;
		}
		// Middle bottom to middle right side 
		i = mid_col + 1;
		j = 1;
		while (i <= e_col && k > 0) {
			print(" ", matrix[(e_row) - j][i],terminator:"");
			i += 1;
			k -= 1;
			j += 1;
		}
		// Middle right side to  top middle 
		i = e_col - 1;
		j = 1;
		while (i > mid_col && k > 0) {
			print(" ", matrix[(mid_row) - j][i],terminator:"");
			i -= 1;
			k -= 1;
			j += 1;
		}
		if (s_row + 1 <= e_row - 1 && k > 0) {
			self.spiral_view(matrix, s_row + 1, s_col + 1, e_row - 1, e_col - 1, k);
		}
	}
	func diamond_spiral(_ matrix: [
		[Int]
	]) {
		let row: Int = matrix.count;
		let col: Int = matrix[0].count;
		//Check whether the given matrix is a valid odd shape or not

		if (row != col || col % 2 == 0) {
			print("\nNot a valid perfect Odd square matrix");
			return;
		}
		self.spiral_view(matrix, 0, 0, row - 1, col - 1, (row * col) - ((col + 1) / 2) * 4);
	}
}
func main() {
	let obj: MyMatrix = MyMatrix();
	//Define matrix 
	let matrix: [
		[Int]
	] = [
		[1, 2, 3, 4, 5],
		[6, 7, 8, 9, 10],
		[11, 12, -1, 15, 16],
		[17, 18, 19, 20, 21],
		[22, 23, 24, 25, 26]
	];
	obj.diamond_spiral(matrix);
}
main();

Output

  3  7  11  18  24  20  16  9  8  12  19  15  -1
<?php
/*
  Php Program
  Anticlockwise spiral view of diamond element in matrix
*/
class MyMatrix {
	// Method which is displaying the Anticlockwise spiral 
	// Of matrix in diamond(mid) element
	function spiral_view($matrix, $s_row, $s_col, $e_row, $e_col, $k) {
		//Find the middle column
		$mid_col = $s_col + intval(($e_col - $s_col) / 2);
		//Get middle row (valid for odd square matrix)
		$mid_row = $mid_col;
		// Matrix are divided into 4 section
		// Starting of middle row and column in form of top
		// Top to Left-bottom

		for ($i = $mid_col, $j = 0; $i > $s_col && $k > 0; $i--, $k--, $j++) {
			echo(" ". $matrix[$s_row + $j][$i]);
		}
		// Middle left to middle right bottom

		for ($i = $s_col, $j = 0; $i <= $mid_col && $k > 0; $i++, $k--, $j++) {
			echo(" ". $matrix[($mid_row) + $j][$i]);
		}
		// Middle bottom to middle right side 

		for ($i = $mid_col + 1, $j = 1; $i <= $e_col && $k > 0; $i++, $k--, $j++) {
			echo(" ". $matrix[($e_row) - $j][$i]);
		}
		// Middle right side to  top middle 

		for ($i = $e_col - 1, $j = 1; $i > $mid_col && $k > 0; $i--, $k--, $j++) {
			echo(" ". $matrix[$mid_row - $j][$i]);
		}
		if ($s_row + 1 <= $e_row - 1 && $k > 0) {
			//Recursive call
			$this->spiral_view($matrix, $s_row + 1, $s_col + 1, $e_row - 1, $e_col - 1, $k);
		}
	}

	function diamond_spiral($matrix) {
		$row = count($matrix);
		$col = count($matrix[0]);
		//Check whether the given matrix is ​​a valid odd shape or not

		if ($row != $col || $col % 2 == 0) {
			//When Yes not a valid size

			echo("\nNot a valid perfect Odd square matrix");
			return;
		}
		//(row*col)-((col+1)/2)*4 are provide the value of number of 
		// diamond element
		$this->spiral_view($matrix, 0, 0, $row - 1, $col - 1, ($row *$col) - intval(($col + 1) / 2) *4);
	}
};

function main() {
	$obj = new MyMatrix();
	//Define matrix 
	$matrix = array(array(1, 2, 3, 4, 5), array(6, 7, 8, 9, 10), array(11, 12, -1, 15, 16), array(17, 18, 19, 20, 21), array(22, 23, 24, 25, 26));
	$obj->diamond_spiral($matrix);
}
main();

Output

 3 7 11 18 24 20 16 9 8 12 19 15 -1
/*
 Node Js Program
  Anticlockwise spiral view of diamond element in matrix
*/
class MyMatrix {
	// Method which is displaying the Anticlockwise spiral 
	// Of matrix in diamond(mid) element
	spiral_view(matrix, s_row, s_col, e_row, e_col, k) {
		//Find the middle column
		var mid_col = s_col + parseInt((e_col - s_col) / 2);
		//Get middle row (valid for odd square matrix)
		var mid_row = mid_col;
		// Matrix are divided into 4 section
		// Starting of middle row and column in form of top
		// Top to Left-bottom

		for (var i = mid_col, j = 0; i > s_col && k > 0; i--, k--, j++) {
			process.stdout.write(" " + matrix[s_row + j][i]);
		}
		// Middle left to middle right bottom

		for (var i = s_col,j = 0; i <= mid_col && k > 0; i++, k--, j++) {
			process.stdout.write(" " + matrix[(mid_row) + j][i]);
		}
		// Middle bottom to middle right side 

		for (var i = mid_col + 1,j = 1; i <= e_col && k > 0; i++, k--, j++) {
			process.stdout.write(" " + matrix[(e_row) - j][i]);
		}
		// Middle right side to  top middle 

		for (var i = e_col - 1,j = 1; i > mid_col && k > 0; i--, k--, j++) {
			process.stdout.write(" " + matrix[(mid_row) - j][i]);
		}
		if (s_row + 1 <= e_row - 1 && k > 0) {
			//Recursive call
			this.spiral_view(matrix, s_row + 1, s_col + 1, e_row - 1, e_col - 1, k);
		}
	}
	diamond_spiral(matrix) {
		var row = matrix.length;
		var col = matrix[0].length;
		//Check whether the given matrix is ​​a valid odd shape or not

		if (row != col || col % 2 == 0) {
			//When Yes not a valid size

			process.stdout.write("\nNot a valid perfect Odd square matrix");
			return;
		}
		//(row*col)-((col+1)/2)*4 are provide the value of number of 
		// diamond element
		this.spiral_view(matrix, 0, 0, row - 1, col - 1, (row *col) - parseInt((col + 1) / 2) *4);
	}
}

function main(args) {
	var obj = new MyMatrix();
	//Define matrix 
	var matrix = [
		[1, 2, 3, 4, 5],
		[6, 7, 8, 9, 10],
		[11, 12, -1, 15, 16],
		[17, 18, 19, 20, 21],
		[22, 23, 24, 25, 26]
	];
	obj.diamond_spiral(matrix)
}
main();

Output

 3 7 11 18 24 20 16 9 8 12 19 15 -1

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment







© 2021, kalkicode.com, All rights reserved