Class of a spiral matrix

xiaoxiao2021-03-06  37

//// Helixmatrix.h: interface for the matrix class.// purpose: create & print helixmatrix // author: hcj // Date: 2005/1/5 //

#ifndef _helixmatrix # define _helixmatrix

#if _MSC_VER> 1000 # prgma overce # endif //_MSC_VER> 1000

Class Helixmatrix {public: helixmatrix (); Helixmatrix (int N); Helixmatrix (int M, int N); virtual ~ helixmatrix () {delete m_pmatrix;}

void print (); // print the matrix void clear (); // clear the matrix with 0 void FillDeasil (); // Deasil fill matrix void FillWiddershins (); // Widdershins fill matrixprivate: int * m_pMatrix; int m_m; INT M_N;

}; # endif //// Matrix.cpp: Implementation of the matrix class.// Purpose: Create & Print Helixmatrix // Author: hcj // Date: 2005/1/5 //

#include "matrix.h" #include #include Using Namespace STD;

// Constructorhelixmatrix :: helixmatrix () {m_m = 4; m_n = 4; m_pmatrix = new int [m_m * m_n]; this-> clear ();

Helixmatrix :: Helixmatrix (int N) {m_m = n; m_n = n; m_pmatrix = new int [m_m * m_n]; this-> clear ();

Helixmatrix :: Helixmatrix (INT M, INT N) {m_m = m; m_n = n; m_pmatrix = new int [M_M * m_n]; this-> clear ();}

// destructor // inline helixmatrix :: ~ helixmatrix () // {// delete m_pmatrix; //}

// clear the element with number 0void helixmatrix :: clear () {for (int i = 0; i

// deasil fill the helixmatrix void helixmatrix :: FillDeasil () {// clear the array this-> clear (); int count = 0; int h = m_m; int 1; int stepx = L; int stepy = h -1; int x = 0; int y = 0; INT i = 0;

While (count! = h * L) {// Fill from left to right if (count! = h * L) {for (i = 0; i

IF (count! = h * L) {for (i = 0; i

}

// Widdershins Fill Helixmatrix with Integer

Void helixmatrix :: fillwiddershins () {

// Clear the array

This-> clear (); int count = 0; int h = m_m; int 1; int adjust = l-1; int adjust = h; int x = 0; int y = 0; INT i = 0;

While (count! = h * L) {// Fill from Up to Down if (count! = h * L) {for (i = 0; i

IF (count! = h * L) {for (i = 0; i using namespace std;

#include "matrix.h"

Int main () {Helixmatrix Matrix; Matrix.Filldeasil (); Matrix.print (); //matrix.clear (); cout << "------------------ --------------------------- "<< endl; matrix.fillwiddershins (); matrix.print (); cout << ------------------------------------------ "<< Endl; Helixmatrix Matrix1 (6); matrix1.filldeasil (); matrix1.print (); cout <<< -------------------------------------------------------------------------------------------------------------------------------------------------- --------------- << endl; //matrix1.clear (); matrix1.fillwiddershins (); matrix1.print (); cout << "------ -------------------------------------- "<< Endl; Helixmatrix Matrix2 (5, 4 ); Matrix2.filldeasil (); matrix2.print (); //matrix2.clear (); cout <<< ------------------------ --------------------- "<< endl; matrix2.fillwiddershins (); matrix2.print (); return 0;}

转载请注明原文地址:https://www.9cbs.com/read-72359.html

New Post(0)