Beispiel #1
0
const aghMatrix<char> aghMatrix<char>::operator*(const aghMatrix<char>& A)
{
   aghMatrix<char> Temp(wier, A.kol);

   for(int i=0; i<wier; i++)
      for(int j=0; j<A.kol; j++)
         Temp.tab[i][j]=0;

   if(kol==A.wier)
   {
      for (int i=0; i<wier; i++)
          for (int j=0; j<A.kol; j++)
         {
            for (int p=0; p<kol; p++)
            {
               Temp.tab[i][j] = Temp.tab[i][j] +  ((tab[i][p]-'a') * (A.tab[p][j]-'a'))  % (( 'z' - 'a') +1 ) ;
            }
            Temp.tab[i][j] = Temp.tab[i][j] % ( ('z' - 'a') +1 ) + 'a';
         }

   Temp.wier=wier;
   Temp.kol=A.kol;


   return Temp;
   }
   else
   throw aghException(0, "Zle rozmiary macierzy", __FILE__, __LINE__);

}
Beispiel #2
0
void aghMatrix<char*>::setItem(int r, int c, char* elem)
{
     if( r>=0 && r<=wier && c>=0 && c<=kol)
     {
        if(tab[r][c] != NULL)
           delete[] tab[r][c];

        if(elem != NULL) {
           tab[r][c] = new char[strlen(elem) + 1];
           strcpy(tab[r][c], elem);
     }
     else
           throw aghException(0, "Nieprawidlowy index", __FILE__, __LINE__);
   }
}
Beispiel #3
0
T& aghDlist<T>::at(int n) const{
  node *temp = NULL;
  temp = head;
  
  if( n < 0 || n > list_lenght )
    throw aghException(0,"incorrect range",__FILE__,__LINE__);
  else{
    for (int i=0; i<n; i++)
      if(temp->next != NULL)
	temp = temp->next;
    
    //cout << temp->item << endl;
    return temp->item;
  }
  
}
Beispiel #4
0
bool aghDlist<T>::insert(int n, T const& item){
  
  if ( n < 0 || n > list_lenght )
    throw aghException(0,"incorrect range",__FILE__,__LINE__);
  else{
    node *temp = new node;
    node *finder = NULL;
    
    if ( list_lenght == 0 ){
      head = temp;
      tail = temp;
      head->next = NULL;
      head->prev = NULL;
    }
    else if (list_lenght == n) 
      {
	
	tail->next = temp;
	temp->prev = tail;
	temp->next = NULL;
	tail = temp;
      }
    
    else if ( n == 0 ){
      temp->next = head;
      head->prev = temp;
      head = temp;
      head->prev = NULL;
    }
    else{
      finder = head;
      for (int i=0; i<n-1; i++)
	finder = finder->next;
      
      temp->next = finder->next;
      temp->prev = finder;
      
      delete finder;
    }
    
    temp->item = item;
    list_lenght++;
  }
  return 1;        
}
Beispiel #5
0
const aghMatrix<char> aghMatrix<char>::operator+(const aghMatrix<char>& A)
{
   aghMatrix<char> Temp(wier, kol);
   if(wier==A.wier && kol==A.kol)
   {
      for(int i = 0; i < wier; i++)
         for(int j = 0; j < kol; j++)
            {  if( ((int(tab[i][j])-97) + (int(A.tab[i][j])-97) )<=25)
                   Temp.tab[i][j]=char( (int(tab[i][j])-97) + (int(A.tab[i][j])-97)  + 97);
               else
                   Temp.tab[i][j]=char( (int(tab[i][j])-97) + (int(A.tab[i][j])-97)  + 97 - 26);
            }
      Temp.wier=wier;
      Temp.kol=kol;

      return Temp;
   }
   else
   throw aghException(0, "Macierze nie sa takie same", __FILE__, __LINE__);
}
Beispiel #6
0
const aghMatrix<char*> aghMatrix<char*>::operator+(aghMatrix<char*> const& A)
{
   aghMatrix<char*> Temp(wier, kol);
   if(wier==A.wier && kol==A.kol)
   {
      for(int i = 0; i < wier; i++)
         for(int j = 0; j < kol; j++)
         {

            char *wyr1, *wyr2;
            int dl1, dl2, il=0;
            wyr1=tab[i][j];
            wyr2=A.tab[i][j];


            dl1 = strlen(wyr1);
            dl2 = strlen(wyr2);
              char* bufor = new char[dl1 + dl2 + 1];

            for(int k = 0; k < dl1; k++)
               if(strchr(bufor, wyr1[k]) == NULL)
                   bufor[il++] = wyr1[k];

            for(int k = 0; k < dl2; k++)
               if(strchr(bufor, wyr2[k]) == NULL)
                 bufor[il++] = wyr2[k];

            bufor[il] = '\0';
            Temp.tab[i][j]  = new char[il + 1];
            strcpy(Temp.tab[i][j] , bufor);
            delete [] bufor;

         }
      Temp.wier=wier;
      Temp.kol=kol;

      return Temp;
   }
   else
   throw aghException(0, "Zle rozmiary macierzy", __FILE__, __LINE__);
}
Beispiel #7
0
bool aghDlist<T>::remove(int n){
  
  if ( n < 0 || n > list_lenght -1 )
    throw aghException(0,"Wrong range",__FILE__, __LINE__);
  else{
    node *temp = NULL;
    temp = head;
    if (n == 0){
      if ( head->next != NULL){
	head = temp->next;
	delete temp;
	head->prev = NULL;
      }
      else if(head == tail){
	delete head;
	head = NULL;
	tail = NULL;
      }
    }
    else if ( n == list_lenght - 1 ) {
      temp = tail->prev;
      delete tail;
      temp->next = NULL;
      tail = temp;
    }
    else{
      for (int i=0; i<n-1; i++)
	temp = temp->next;
      temp->next = temp->next->next;
      delete temp->next->prev;
      temp->next->prev = temp;
    }
    list_lenght--;
    return 1;
  } 
  

  return 0;
}
Beispiel #8
0
const aghMatrix<char*> aghMatrix<char*>::operator*(aghMatrix<char*> const& A)
{
   aghMatrix Temp(wier, A.kol);
   if(kol==A.wier)
   {
      for(int i = 0; i < wier; i++)
         for(int j = 0; j < A.kol; j++)
            for (int p=0; p<kol; p++)
            {
                char* result = NULL;
                char *c1, *c2;
                c1=tab[i][p];
                c2=A.tab[p][j];

                int c1Length = strlen(c1);
                int c2Length = strlen(c2);

                char* buffer = new char[((c1Length > c2Length) ? c1Length : c2Length) + 1];

                int counter = 0;
                for(int k = 0; k < c1Length; k++)
                {
                   char temp = c1[k];
                   if(strchr(c2, temp) != NULL)
                   if(strchr(buffer, temp) == NULL)
                      buffer[counter++] = temp;
                }


                buffer[counter] = '\0';
                result = new char[counter + 1];
                strcpy(result, buffer);
                delete[] buffer;

                char* kopia1=Temp.tab[i][j];
                char* kopia2=result;

                char* result1;
                char* a=kopia1;
                char* b=kopia2;
                int a_Length, b_Length;

                if(a == NULL)
                   a_Length = 0;
                else
                   a_Length = strlen(a);

                if(b == NULL)
                   b_Length = 0;
                else
                  b_Length = strlen(b);

                char* buffer1 = new char[a_Length + b_Length + 1];

                int licznik = 0;
                for(int k = 0; k < a_Length; k++)
                   if(strchr(buffer1, a[k]) == NULL)
                      buffer1[licznik++] = a[k];

                for(int k = 0; k < b_Length; k++)
                   if(strchr(buffer1, b[k]) == NULL)
                      buffer1[licznik++] = b[k];

                buffer1[licznik] = '\0';
                result1 = new char[licznik + 1];
                strcpy(result1, buffer1);
                Temp.tab[i][j]=result1;
                delete[] buffer1;
        }
        return Temp;
        }
        else
          throw aghException(0, "Zle rozmiary macierzy", __FILE__, __LINE__);

}