bool GeneralMatrix::ExchangeRows(int iRow1,int iRow2) const
{
         int j;
	ELEMTYPE temp;

    if(this->nRow()<2||iRow1==iRow2)
		return TRUE;

    if(iRow1>=nRow()||iRow2>=nRow())
        return FALSE;
	
    for(j=0;j<nCol();j++)
	{
                 temp = GetElem(iRow1,j);
     GetElem(iRow1,j) = GetElem(iRow2,j);
	 GetElem(iRow2,j) = temp;         
	}

return TRUE;   
}
bool GeneralMatrix::ExchangeCols(int iCol1,int iCol2) const
{
	int i;
	ELEMTYPE temp;

    if(this->nCol()<2||iCol1==iCol2)
		return TRUE;
	
    if(iCol1>=nCol()||iCol2>=nCol())
        return FALSE;

    for(i=0;i<nRow();i++)
	{
		          temp = GetElem(i,iCol1);
      GetElem(i,iCol1) = GetElem(i,iCol2);
      GetElem(i,iCol2) = temp;
	}

return TRUE;
}
bool GeneralMatrix::MakeUnit() const
{
	if(nRow()!=nCol())
		return FALSE;

    Zero();

	for (int i=0;i<nRow();i++)
	    GetElem(i,i) = 1.0;

return TRUE;	
}
void unionL(SqList *La,SqList Lb)
{
	ElemType e;
	int La_len=ListLength(*La);
	int Lb_len=ListLength(Lb);
	for (int i=1;i<=Lb_len;i++)
	{
		GetElem(Lb,i,&e);
		if (!LocateElem(*La,e))
			ListInsert(La,++La_len,e);
	}
}
Example #5
0
void Union(List &La, List Lb) {  // 算法2.1
  // 将所有在线性表Lb中但不在La中的数据元素插入到La中
  int La_len,Lb_len,i;
  ElemType e;
  La_len = ListLength(La);          // 求线性表的长度  
  Lb_len = ListLength(Lb);
  for (i=1; i<=Lb_len; i++) {
    GetElem(Lb, i, e);              // 取Lb中第i个数据元素赋给e
    if (!LocateElem(La, e, equal))  // La中不存在和e相同的数据元素
      ListInsert(La, ++La_len, e);  // 插入
  }
} // union
GeneralMatrix GeneralMatrix::GetColVector(int iCol) const
{
	int i;
	GeneralMatrix Vector(nRow(),1,ERRORVAL);
	
	if(iCol<0||iCol>nCol()-1||nRow()==0) return Vector;
	
	for(i=0;i<nRow();i++)
		Vector[i][0] = GetElem(i,iCol);
	
return Vector;
}
Example #7
0
/**************************************************************************
* name       : FindElem
* description: 查找元素
* input      : pszElemName 待查找的元素名
* output     : NA
* return     : true - 成功,false - 失败
* remark     : NA
**************************************************************************/
bool CXml::FindElem(const char *pszElemName)
{
    CHECK_POINTER(pszElemName, false);
    CHECK_POINTER(m_pXmlNode, false);

    TiXmlNode* pTmpNode = m_pXmlNode;

	// 将指针指向第一个元素
	m_pXmlNode = m_pXmlNode->Parent()->FirstChild();

    // 判断指针是否为空
    CHECK_POINTER(m_pXmlNode, false);

	m_pXmlElem = m_pXmlNode->ToElement();

	// 增加一个变量检查控制情况
	const char* pChkTmpNode = NULL;
    while (((pChkTmpNode = GetElem()) != NULL) && (0 != strcmp(pszElemName, pChkTmpNode))) //lint !e838
    {
        if (NULL == m_pXmlNode->NextSibling())
        {
            break;
        }

        m_pXmlNode = m_pXmlNode->NextSibling();
        m_pXmlElem = m_pXmlNode->ToElement();
    }
/*
	while (0 != strcmp(pszElemName, GetElem()))
    {
        if (NULL == m_pXmlNode->PreviousSibling())
        {
            return false;
        }

        m_pXmlNode = m_pXmlNode->PreviousSibling();
        m_pXmlElem = m_pXmlNode->ToElement();
    }
*/
	const char* pNextTmpElem = this->GetElem();
	CHECK_POINTER(pNextTmpElem, false);
    if (0 == strcmp(pszElemName, pNextTmpElem))
    {
        return true;
    }

	// 如果找不到匹配节点,指针还原
	m_pXmlNode = pTmpNode;
	m_pXmlElem = m_pXmlNode->ToElement();
	
    return false;
}
GeneralMatrix GeneralMatrix::GetDiagonalVector() const
{
	int i;

	GeneralMatrix Vector(nRow(),1,ERRORVAL);

    if (nRow()!=nCol())
        return Vector;

	for(i=0;i<nRow();i++)
		Vector[i][0] = GetElem(i,i);
return Vector;
}
ELEMTYPE GeneralMatrix::Distance_E(GeneralMatrix& other) const
{
	     int i,j; 
	ELEMTYPE result = ERRORVAL;

	if(nRow()!=other.nRow()||nCol()!=other.nCol()) return result;

    for(result=0,i=0;i<nRow();i++)
		for(j=0;j<nCol();j++)
		   result += pow(GetElem(i,j)-other[i][j],2);

return sqrt(result);
}
GeneralMatrix GeneralMatrix::GetRowVector(int iRow) const
{
	int j;
		
	GeneralMatrix Vector(1,nCol(),ERRORVAL);

	if(iRow<0||iRow>nRow()-1||nCol()==0) return Vector;

   for(j=0;j<nCol();j++)
	   Vector[0][j] = GetElem(iRow,j);

return Vector;
}
Example #11
0
void GetPowerSet(int i, List A, List &B) {  // 算法6.15
   // 线性表A表示集合A,线性表B表示幂集ρ(A)的一个元素。
   // 局部量k为进入函数时表B的当前长度。
   // 第一次调用本函数时,B为空表,i=1。
   ElemType x;
   int k;
   if (i > ListLength(A)) Output(B); // 输出当前B值,即ρ(A)的一个元素
   else { 
      GetElem(A, i, x);        k = ListLength(B);
      ListInsert(B, k+1, x);   GetPowerSet(i+1, A, B);
      ListDelete(B, k+1, x);   GetPowerSet(i+1, A, B);
   }
} // GetPowerSet
bool GeneralMatrix::Paste(GeneralMatrix& other,int top,int left) const
{
 int i,j,iRow,iCol;

 iRow = other.nRow()>(nRow()-top)  ? (nRow()-top) : other.nRow();
 iCol = other.nCol()>(nCol()-left) ? (nCol()-left): other.nCol();
 
 for(i=0;i<iRow;i++)
	 for(j=0;j<iCol;j++)
		 GetElem(i+top,j+left) = other[i][j];

return TRUE;
}
Example #13
0
File: List.c Project: chinabin/DSAA
// replace element of position index, so original element will toward back
bool ListInsert(pListHeader plh, unsigned int index, pListNode pNode)
{
    if(index > plh->ListSize)
        ErrorFunc("Too much bigger index!\n", OUT_OF_SCOPE);

    pListNode pRplcedNode = GetElem(plh, index);
    pListNode pPriorNode = PriorElem(plh, pRplcedNode);

    pNode->next = pPriorNode->next;
    pPriorNode->next = pNode;

    (plh->ListSize)++;
    return true;
}
Example #14
0
void Constraint::LinkToElements() 
{
	if (UsePenaltyFormulation()) //in penalty formulation, the SOS-DOF are hired from constrained elements
	{
		LinkToElementsPenalty();
	}
	else
	{
		for (int i = 1; i <= NE(); i++) //$ DR 2012-11-02: changed elements.Length() to NE(), because some constraints add element(2) = 0 for ground joints, NE() returns the correct value for these constraints 
		{
			GetElem(i).AddConstraint(this,i);
		}
	}
}
void main()
{
	int *e;
    Linklist L;
	e=(int *)malloc(sizeof(int));
    L=(Linklist)malloc(LEN);
	Init_Link(L);
	Show_Link(L);
	Insert_List(L,17,2);
    Show_Link(L);
	GetElem(L,2,e);
	printf("%d\n",*e);
	free(e);
}
Example #16
0
/*====================================================================
*	操作目的: 输出顺序表中的元素
*
*	初始条件: 线性表L已存在
*
*	操作结果: 输出了顺序表中的元素
*
*	函数参数:
*		SeqList *L	线性表L
*
*	返回值:
*		无
======================================================================*/
void Show_Elem(SeqList *L)
{
	int i;
	DataType e;
	for(i = 0; i < L->length; i++)
	{
		if(GetElem(*L, i+1, &e) == false)
		{
			fprintf(stderr,"输出失败!\n");
			exit(EXIT_FAILURE);
		}
		printf("%4d", e);
	}
}
Example #17
0
void unionL(SqList *La, SqList Lb) /* union Lb to La */
{				
    int La_len, Lb_len, i;
    ElemType e;
    La_len = ListLength(*La);
    Lb_len = ListLength(Lb);

    for (i = 1; i <= Lb_len; ++i) {
	GetElem(Lb, i, &e);
	if (!LocateElem(*La, e))
	    ListInsert(La, ++La_len, e);
    }
    
}
Example #18
0
void Union(SqList &La, SqList &Lb)
{
//将所有在线性表Lb中但不在La中的数据元素插入到La中
	ElemType e;
	//int La_len, Lb_len;
	int i;
	//La_len = ListLength(La);
	//Lb_len = ListLength(Lb);
	for ( i = 1; i <= Lb.length; i++ )
	{
		GetElem(Lb, i, e);
		if ( !LocateElem(La, e, equal) )
			ListInsert(La, ++La.length, e);
	}
}
Example #19
0
//#endif
//********************************************************************
//删除A中出现B的元素的函数实现
void DelElem(SeqList *A,SeqList B)
{
	int i,flag,pos;
	DataType e;
	for(i=0;i<B.length;i++)
	{
		flag=GetElem(B,i,&e);//依次把B中每个元素取出给
		if(flag==1)
		{
			pos=LocateElem(*A,e);//在A中查找和B中取出的元素e相等的元素
			if(pos>0)
				DeleteList(A,pos,&e);//如果找到该元素,将其从A中删除
		}
	}
}
Example #20
0
int main() {
	student s;
	SqList L;

	InitList_Sq(L);
	s.score = 60; s.boy = true;
	ListInsert_Sq(L, 1, s);
	s.score = 70; s.boy = false;
	ListInsert_Sq(L, 1, s);
	s.score = 90; s.boy = false;
	ListInsert_Sq(L, 2, s);

	int n = Length(L);// int n = L.length;
	for (int i = 1; i <= n; i++) {
		GetElem(L, i, s);
		std::cout << s.score << " " << s.boy << "\n";
	}

	ListDelete_Sq(L, 1, s);
	std::cout << "删除的1号元素是:"<<s.score << " " << s.boy << "\n";

	n = Length(L);
	for (int i = 1; i <= n; i++) {
		GetElem(L, i, s);
		std::cout << s.score << " " << s.boy << "\n";
	}

	double average_score = 0;
	for (int i = 1; i <= n; i++) {
		GetElem(L, i, s);
		average_score += s.score;
	}
	average_score /= n;
	std::cout << "平均分是" << average_score << "\n";
	return 0;
}
Example #21
0
icSigBRDFFunction CIccStructBRDF::GetBRDFFunction() const
{
  CIccTag* pTag = GetElem(icSigTypeBrdfMember);

  if (pTag)
  {
    if (pTag->GetType() == icSigSignatureType)
    {
      CIccTagSignature* pTagSig = dynamic_cast<CIccTagSignature*>(pTag);
      if (pTagSig)
        return  (icSigBRDFFunction)pTagSig->GetValue();
    }
  }
  return (icSigBRDFFunction)icSigUnknownType;
}
Example #22
0
void union_func(SqList *La, SqList Lb)
{
	int La_length, Lb_length, i;

	ElemType e;
	La_length = ListLength(*La);
	Lb_length = ListLength(Lb);
	
	for( i=1; i <= Lb_length; i++) {
		GetElem(Lb, i, &e);
		if( !LocateElem(*La, e) ) {
			ListInsert(La, ++La_length, e);
		}
	}
}
nsIContent*
IDRefsIterator::NextElem()
{
  while (true) {
    const nsDependentSubstring id = NextID();
    if (id.IsEmpty())
      break;

    nsIContent* refContent = GetElem(id);
    if (refContent)
      return refContent;
  }

  return nsnull;
}
void GeneralMatrix::Print()
{
	if (nRow()==0||nCol()==0)
	{
		return;
	}
	for (int i=0;i<nRow();i++)
	{
		for (int j=0;j<nCol();j++)
		{
			cout<<GetElem(i,j)<<" ";
		}
		cout<<endl;
	}
	cout<<endl;
}
Example #25
0
void Union1(Sqlist &La, Sqlist &Lb)
{
    ElemType e;
    int i;
    int la_len, lb_len;
    la_len = ListLength(La);
    lb_len = ListLength(Lb);

    for ( i = 1; i <= lb_len; i++ )
    {
        GetElem(Lb, i, e);
        printf("e = %d\n", e);
        if ( !LocateElem(La, e, equal) )
            ListInsert_before(La, ++la_len, e);
    }
}
Example #26
0
void unionL(sqList *La,sqList Lb)
{
	int La_len,Lb_len,i;
	ElemType e;
	
	La_len =ListLength(*La);
	Lb_len =ListLength(Lb);
	
	for (i=1; i< Lb_len;i++) {
		GetElem(Lb,i,&e);
		if(!LocateElem(*La,e))
		{
			ListInsert(La,++La_len,e);
		}
	}
}
Example #27
0
//在双向循环链表的第i个位置插入元素e。插入成功返回1,否则返回0
int InsertDList(DLinkList head,int i,char e){
	DListNode *p,*s;
	p=GetElem(head,i);	//查找链表中第i个结点
	if(!p)
		return 0;
	s=(DListNode *)malloc(sizeof(DListNode));
	if(!s)
		return -1;
	s->data=e;
	//将s结点插入到双向循环链表
	s->prior=p->prior;
	p->prior->next=s;
	s->next=p;
	p->prior=s;
	return 1;
}
Example #28
0
void DelElem(SeqList *A, SeqList B)
{
	int i, pos;
	DataType e;

	for(i = 0; i < B.length; i++)
	{
		if(GetElem(B, i + 1, &e)) /* 依次把B中的每个元素取出来 */
		{
			if( (pos = LocateList(*A, e, compare )) >= 1)
				ListDelete(A, pos, &e );
		}

	}

}
Example #29
0
int main()
{
	SqList L;
	printf("%ld\n",sizeof(L));
	InitSqList(L);
	int i;
	for(i=0;i<20;++i)
		push_back(L,i);
	Display(L);
	printf("L.length :%d\n",L.length);
	printf("listlength:%d\n",ListLength(L));
	Elem e,prio,next;
	GetElem(L,2,e);
	PriorElem(L,prio,e);
	NextElem(L,next,e);
	printf("the number 2 tumple:%d\n",e);
	printf("prio e:%d\n",prio);
	printf("next e:%d\n",next);
	ListInsert(L,8,10000);
	Display(L);
	LocateList(L,10000);
	DeleteK(L,5,3);
	Display(L);
	DestroyList(L);
	printf("size of a.length :%d\n",L.listsize);
	if(ListEmpty(L))
		printf("empty!\n");
	
	/*char* p = NULL;
	p=(char*)malloc(10*sizeof(char));
	if(p==NULL)
	{
		printf("filure");
		exit(1);
	}
	printf("%p\n",p);

	strcpy(p,"abc");
	printf("%c\n%c\n%c\n",*p,*p+1,*p+2);
	printf("%p\n%p\n",p,p+1);
	//if(p!=NULL)
		free(p);
	//p=NULL;
	
	//DestroyList(L);
	//Display(L);*/ return 0;
}
Example #30
0
File: List.c Project: chinabin/DSAA
void ListDelete(pListHeader plh, unsigned int index)
{
    pListNode pNode = GetElem(plh, index);
    pListNode tmp = pNode;
    if(index == 1)
    {
        plh->next = pNode->next;
    }
    else
    {
        pListNode pPriorNode = PriorElem(plh, pNode);
        pPriorNode->next = pNode->next;
    }

    free(tmp);
    (plh->ListSize)--;
}