Пример #1
0
void main ( void )
{
	Row *pMatr;	// a pointer to the first element of the first row of of the matrix
	unsigned char rows = 2U;		// count of the rows of the matrix
	unsigned char colls = 2U;	// count of the rows of the matrix
	
	do
	{
		system("cls");
		printf("The minimum size of of the matrix: %hhu x %hhu.\n", MIN_SIZE, MIN_SIZE);
		printf("The maximum size of of the matrix: %hhu x %hhu.\n\n", MAX_SIZE, MAX_SIZE);
		
		//	input size of the matrix 
		printf("Enter count of rows (0 - continue): "); 
		if(ProtectionInput(rows, MIN_SIZE, MAX_SIZE) == false)
		{
			printf("\nInput data terminated by user.\n");
			continue;
		}
		printf("Enter count of colls (0 - continue): ");
		if(ProtectionInput(colls, MIN_SIZE, MAX_SIZE) == false)
		{
			printf("\nInput data terminated by user.\n");
			continue;
		}
	
		system("cls");

		printf("Size of matrix: %hhu x %hhu\n", rows, colls);

		// enter of the matrix
		pMatr = CreateMatrList(rows, colls);
		if(pMatr == NULL)
		{
			printf("\nMatrix is not created.\n");
			continue;
		}
		// displays a matrix
		PrintMatrList(pMatr, colls);

		// delete rows
		unsigned char countDel = DelRows(pMatr, colls);
		printf("%u row(s) removed from the matrix.\n", countDel);

		// displays a matrix
		PrintMatrList(pMatr, colls);
		delete pMatr;
	}
	while(CONTINUE, _getch() != CODE_ESC);	// while not pressed key ESC...
	return;
}
bool GeneralMatrix::AddRows(int in,ELEMTYPE Val)const
{
         int i,j,index=0;
   ElemNode *p,*pnew,*pL; 
   
   if (in==0) return FALSE;

   if (in<0) return DelRows(in*-1);

   if(pHead->pFirst==NULL)
   {
	   this->pHead->pFirst = new ElemNode;

        if(pHead->pFirst == NULL)
			return FALSE;

       pHead->nRow = 1;
	   pHead->nCol = 1;
	   pHead->pFirst->pDown = NULL;
	   pHead->pFirst->pRight = NULL;
	   pHead->pFirst->val = Val;
	   index = 1;
   }

   i = pHead->nRow-1;
   for(;index<in;index++,i++,pHead->nRow++)
	   for(pL=NULL,j=0;j<pHead->nCol;j++)
	   {
            p = GetElemP(i,j);
         pnew = new ElemNode;
		     if(pnew==NULL) return FALSE;

			 pnew->pDown  = NULL;
			 pnew->pRight = NULL;
			 pnew->val    = Val;
			 
			 if(pL!=NULL)
				 pL->pRight = pnew;
			 
			     pL = pnew;
		   p->pDown = pnew;
	   }

return TRUE;
}