int main()
{	LinkList *L1,*L2;
	int b,e;
	InitList( L1 );
	InitList( L2 );
	puts("Add ax^b to L1,please input \"a b\"");
	while(scanf("%d%d",&b,&e) == 2)
	{	if( 0 == b)break;
		InsertList( L1, b, e);
		DispList( L1);
		puts("input \"a b\"");
	}
	puts("Add ax^b to L2,please input \"a b\"");
	while(scanf("%d%d",&b,&e) == 2)
	{	if( 0 == b)break;
		InsertList( L2, b, e);
		DispList( L2);
		puts("input \"a b\"");
	}
	printf("End inputs:\n");
	printf("1:  ");DispList( L1);
	printf("2:  ");DispList( L2);
	puts("Add:");
	Add( L1, L2);
	DispList( L1);
	return 0;
}
Exemple #2
0
/*合并顺序表A和B的元素到C中,并保持元素非递减排序*/
void MergeList(SeqList a,SeqList b,SeqList *c)
{
	int i,j,k;
	i=1;
	j=1;
	k=1;
	DataType e1,e2;
	while(i<=a.length&&j<=b.length)
	{
		GetElem(a,i,&e1);//取出顺序表A中的元素
		GetElem(b,j,&e2);//取出顺序表B中的元素
		if(e1<=e2)	//比较顺序表A和顺序表B中的元素
		{
			InsertList(c,k,e1);	//将较小的一个插入到C中
			i++;				//往后移动一个位置,准备比较下一个元素
			k++;
		}else{
			InsertList(c,k,e2);
			j++;
			k++;
		}
	}
	while(i<=a.length){		//如果A中元素还有剩余,这时B中已经没有元素
		GetElem(a,i,&e1);
		InsertList(c,k,e1);	//将A中剩余元素插入到C中
		i++;
		k++;
	}
	while(j<=b.length){
		GetElem(b,j,&e2);
		InsertList(c,k,e2);
		j++;
		k++;
	}
}
Exemple #3
0
void main()
{
    int i,j,flag;
    DataType e;
    SeqList A, B;
    InitList(&A);
    InitList(&B);
    for(i=1;i<=10;i++)
    {
        if(InsertList(&A,i,i) == 0)
        {
            printf("位置不合法");
            return;
        }
    }
    for(i=1,j=1;j<=6;i=i+2,j++)
    {
        if(InsertList(&B,j,i*2) == 0)
        {
            printf("位置不合法");
            return;
        }
    }
    printf("顺序表A中的元素:\n");
    for(i=1;i<=A.length;i++)
    {
        flag = GetElem(A,i,&e);
        if(flag==1)
        {
            printf("%4d",e);
        }
    }
    printf("\n");
    printf("顺序表B中的元素:\n");
    for(i=1;i<=B.length;i++)
    {
        flag = GetElem(B,i,&e);
        if(flag == 1)
        {
            printf("%4d",e);
        }
    }
    printf("\n");
    printf("将在A中出现的B的元素删除后的A的元素:\n");
    DelElem(&A,B);
    for(i=1;i<=A.length;i++)
    {
        flag = GetElem(A,i,&e);
        if(flag==1)
        {
            printf("%4d",e);
        }
    }
    printf("\n");
}
Exemple #4
0
/*****************************************************************************************************************************
 Routine to read the Bench Mark(.isc files)
*****************************************************************************************************************************/
int ReadIsc(FILE *fisc,NODE *graph)
{
char c,noty[Mlin],from[Mlin],str1[Mlin],str2[Mlin],name[Mlin],line[Mlin];
int  i,id,fid,fin,fout,mid=0;

// intialize all nodes in graph structure
for(i=0;i<Mnod;i++){ InitializeCircuit(graph,i); } 
//skip the comment lines 
do
fgets(line,Mlin,fisc);
while(line[0] == '*');
// read line by line 
while(!feof(fisc)){
  //initialize temporary strings 
  bzero(noty,strlen(noty));    bzero(from,strlen(from));
  bzero(str1,strlen(str1));    bzero(str2,strlen(str2));   
  bzero(name,strlen(name));
  //break line into data 
  sscanf(line, "%d %s %s %s %s",&id,name,noty,str1,str2); 
  //fill in the type
  strcpy(graph[id].nam,name);
  graph[id].typ=AssignType(noty);
  //fill in fanin and fanout numbers
  if(graph[id].typ!=FROM) {   fout= atoi(str1);  fin=atoi(str2); }    
  else{                       fin=fout= 1; strcpy(from,str1);    }   
  if(id > mid){ mid=id;  }
  graph[id].nfo=fout;  graph[id].nfi=fin;
  if(fout==0){  graph[id].po=1; }
  //create fanin and fanout lists   		  
  switch (graph[id].typ)  {
    case 0     : printf("ReadIsc: Error in input file (Node %d)\n",id); exit(1);
    case INPT  : break;
    case AND   :
    case NAND  :
    case OR    :
    case NOR   :
    case XOR   :
    case XNOR  :
    case BUFF  :
    case NOT   : for(i=1;i<=fin;i++) {
		   fscanf(fisc, "%d", &fid);
                   InsertList(&graph[id].fin,fid);  
                   InsertList(&graph[fid].fot,id); }  
		   fscanf(fisc,"\n");  break; 		   	        	   
    case FROM  : for(i=mid;i>0;i--){
 	   	   if(graph[i].typ!=0){
                     if(strcmp(graph[i].nam,from)==0){  fid=i; break; } } }
                  InsertList(&graph[id].fin,fid);
                  InsertList(&graph[fid].fot,id);   break; 
    } //end case 
  bzero(line,strlen(line)); 
  fgets(line,Mlin,fisc);  
} // end while 
return mid;
}//end of ReadIsc 
Exemple #5
0
void main_MergeList()
{
	int i,flag;
	DataType a[]={6,11,11,23};
	DataType b[]={2,10,12,12,21};
	DataType e;
	SeqList A,B,C;					/*声明顺序表A,B和C*/
	InitList(&A);					/*初始化顺序表A*/
	InitList(&B);					/*初始化顺序表B*/
	InitList(&C);					/*初始化顺序表C*/
	for(i=1;i<=sizeof(a)/sizeof(a[0]);i++)				/*将数组a中的元素插入到顺序表A中*/
	{
		if(InsertList(&A,i,a[i-1])==0)
		{
			printf("位置不合法");
			return;
		}
	}
	for(i=1;i<=sizeof(b)/sizeof(b[0]);i++)				/*将数组b中元素插入到顺序表B中*/
	{
		if(InsertList(&B,i,b[i-1])==0)
		{
			printf("位置不合法");
			return;
		}
	}
	printf("顺序表A中的元素:\n");
	for(i=1;i<=A.length;i++)		/*输出顺序表A中的每个元素*/
	{
		flag=GetElem(A,i,&e);		/*返回顺序表A中的每个元素到e中*/
		if(flag==1)
			printf("%4d",e);
	}
	printf("\n");
	printf("顺序表B中的元素:\n");
	for(i=1;i<=B.length;i++)		/*输出顺序表B中的每个元素*/
	{
		flag=GetElem(B,i,&e);		/*返回顺序表B中的每个元素到e中*/
		if(flag==1)
			printf("%4d",e);	
	}
	printf("\n");
	printf("将在A中出现B的元素合并后C中的元素:\n");
	MergeList(A,B,&C);					/*将在顺序表A和B中的元素合并*/
	for(i=1;i<=C.length;i++)			/*显示输出合并后C中所有元素*/
	{
		flag=GetElem(C,i,&e);
		if(flag==1)
			printf("%4d",e);	
	}
	printf("\n");
	system("pause");
}
void main_2()
{
	SeqList s,*l;
	DataType data = 8;
	l = &s;
//	s.length = 10; 
	printf("=================%d,%d \n",s.length,ListSize);
	InsertList(l,1,data);
	InsertList(l,2,18);
	InsertList(l,3,156);
	showData(l);
	InsertList(l,2,8888);
	showData(l);
}
Exemple #7
0
void main_DelElem()
{
	int i,j,flag;
	DataType e;
	SeqList A,B;					
	InitList(&A);					
	InitList(&B);					
	for(i=1;i<=10;i++)				//将1-10插入到顺序表A中
	{
		if(InsertList(&A,i,i)==0)
		{
			printf("位置不合法");
			return;
		}
	}
	for(i=1,j=1;j<=6;i=i+2,j++)		//插入顺序表B中六个数
	{
		if(InsertList(&B,j,i*2)==0)
		{
			printf("位置不合法");
			return;
		}
	}
	printf("顺序表A中的元素:\n");
	for(i=1;i<=A.length;i++)		
	{
		flag=GetElem(A,i,&e);		//返回顺序表A中的每个元素到e中
		if(flag==1)
			printf("%4d",e);
	}
	printf("\n");
	printf("顺序表B中的元素:\n");
	for(i=1;i<=B.length;i++)		//输出顺序表B中的每个元素
	{
		flag=GetElem(B,i,&e);		//返回顺序表B中的每个元素到e中
		if(flag==1)
			printf("%4d",e);	
	}
	printf("\n");
	printf("将在A中出现B的元素删除后A中的元素:\n");
	DelElem(&A,B);					//将在顺序表A中出现的B的元素删除
	for(i=1;i<=A.length;i++)		//显示输出删除后A中所有元素
	{
		flag=GetElem(A,i,&e);
		if(flag==1)
			printf("%4d",e);	
	}
	printf("\n");
	system("pause");
}
Exemple #8
0
int AddNode(listPtr List, listnodePtr Node)
{
  if (List == NULL) return LLIST_NULL;

  switch (List->Flags & LISTADDMASK) 
    {
       case LISTADDCURR: return InsertList(List, Node); break;
       case LISTADDHEAD: return HeadList(List, Node); break;
       case LISTADDTAIL: return TailList(List, Node); break;
       case LISTADDSPLAY: return SplayInsertList(List, Node); break;
     default: return InsertList(List, Node); break; 
    }

  return LLIST_ERROR;
} /* AddNode() */
Exemple #9
0
void EventList::SendEvent(CTime time,
		char *ProcessID,
		char *ProcessName,
		char *Operation,
		char *addr1,
		char *addr2,
		char *addr3,
		char *addr4,
		char *RemotePort,
		char *LocalPort,
		char *result)
{
	if(DialogHwnd==NULL) return;
	DebugPrint_Event* pEvent = new DebugPrint_Event;
	if( time==0) time = CTime::GetCurrentTime();
	pEvent->Timestamp = time;
	strcpy(pEvent->ProcessID,ProcessID);
	strcpy(pEvent->ProcessName,ProcessName);
	strcpy(pEvent->Operation,Operation);
	strcpy(pEvent->addr1,addr1);
	strcpy(pEvent->addr2,addr2);
	strcpy(pEvent->addr3,addr3);
	strcpy(pEvent->addr4,addr4);
	strcpy(pEvent->RemotePort,RemotePort);
	strcpy(pEvent->LocalPort,LocalPort);
	strcpy(pEvent->SuccOrFail,result);
	::SendMessage( DialogHwnd, WM_SEND_MESSAGE, -1, (LPARAM)pEvent);
	
	InsertList(pEvent);
}
Exemple #10
0
int main()
{
	Node node1, node2, node3, node4, node5;
	
	node1.val = 1;
	node2.val = 2;
	node3.val = 3;
	node4.val = 4;
	node5.val = 5;
	
	node1.next = &node2;
	node2.next = &node3;
	node3.next = &node4;
	node4.next = 0;
	node5.next = 0;
	Node*watchedpNode;
        watchedpNode=&node2;
	Node* watchedpHead;
	watchedpHead = &node1;
	
	InsertList( &node1, &node5, 2 );
	
	while ( watchedpHead != 0 )
	{
		write watchedpHead->val;
		write 1;
		watchedpHead = watchedpHead->next;		
	}
	
	return 0;
}
Exemple #11
0
int		main(void){
	DL node = InitList();
	ShowList(node);

	AddElem(node,1);
	AddElem(node,2);
	AddElem(node,3);
	AddElem(node,4);
	AddElem(node,5);
	printf("%d\n",node->data);
	ShowList(node);

	InsertList(node,3,10);
	printf("%d\n",node->data);
	ShowList(node);

	int e;
	RemoveList(node,3,&e);
	printf("%d %d\n",node->data,e);
	ShowList(node);

	GetElem(node,3);
	printf("%d %d\n",GetElem(node,3),GetElem(node,20));

	ClearList(node);
	ShowList(node);
	free(node);
	return(EXIT_SUCCESS);
}
Exemple #12
0
void d_frontier(NODE *graph,int Max,LIST **frontier)
{
LIST *fanin;
int flag,i,check;


	for(i=0;i<=Max;i++){
	flag = 0;
	check = 0;
		if(graph[i].Type!=0)
			if(graph[i].Cval == 2){
				fanin = graph[i].Fin;
				while(fanin!=NULL){
					if(graph[fanin->id].Cval == 3 || graph[fanin->id].Cval == 4 ){
						flag = 1;
					}
				fanin = fanin->next;
				}
				if(flag == 1){
					x_path(graph,i,&check);
					if(check == 1){
						InsertList(&(*frontier),i);
						break;
					}
				}
			}
	}	
}
void sortedInsert (List l, int val)
{
     struct Node *newNode,*p;
     int i = 0;

     newNode = (struct Node *) malloc(sizeof(struct Node));

     newNode->val = val;
     newNode->next = NULL;


     if (val > l->tail->val)
     {
         l->tail->next = newNode;
         l->tail = newNode;
     }

     else
     {
         p = l->head->next;

         while (p->val < val)
         {
             p = p->next;
             i++;
      //       printf("check ");
         }

         InsertList(l,i,val);
     }
}
Exemple #14
0
void main_SplitSeqList(){
	int i,flag,n;
	DataType e;
	SeqList L;				
	int a[]={-7,0,5,-8,9,-4,3,-2};
	InitList(&L);					/*初始化顺序表L*/
	n=sizeof(a)/sizeof(a[0]);
	for(i=1;i<=n;i++)				/*将数组a的元素插入到顺序表L中*/
	{
		if(InsertList(&L,i,a[i-1])==0)
		{
			printf("位置不合法");
			return;
		}
	}
	printf("顺序表L中的元素:\n");
	for(i=1;i<=L.length;i++)		/*输出顺序表L中的每个元素*/
	{
		flag=GetElem(L,i,&e);		/*返回顺序表L中的每个元素到e中*/
		if(flag==1)
			printf("%4d",e);
	}
	printf("\n");
	printf("将顺序表L调整后(左边元素>=0,右边元素<0):\n");
	SplitSeqList(&L);					/*调整顺序表*/
	for(i=1;i<=L.length;i++)			/*输出调整后顺序表L中所有元素*/
	{
		flag=GetElem(L,i,&e);
		if(flag==1)
			printf("%4d",e);	
	}
	printf("\n");	
	system("pause");
}
Exemple #15
0
int main(){
printf("\nEnter the no of nodes you want to insert in LL: ");
int n;
scanf("%d",&n);
int i;
int data;
//LNode* head=NULL;
TNode* head=NULL;
for(i=0;i<n;i++){
printf("\nEnter data :  ");
scanf("%d",&data);
InsertList(&head,data);
}

printf("\nList created\n");
getch();
printf("\nPress enter to traverse list\n");
getch();
TraverseList(head);
getch();
printf("\nPress enter to create tree \n\n");
getch();
TNode* root=CreateTree_From_DLL(&head,n);
printf("\nTree created\n");
printf("\nPress enter to traverse tree inorder\n\n");
getch();
InOrder(root);
getch();

return 0;
}
Exemple #16
0
MainObject::MainObject(QObject *parent,const char *name)
    : QObject(parent,name)
{
    //
    // Read Command Options
    //
    RDCmdSwitch *cmd=
        new RDCmdSwitch(qApp->argc(),qApp->argv(),"sas_filter",SAS_FILTER_USAGE);
    delete cmd;

    rd_config=new RDConfig(RD_CONF_FILE);
    rd_config->load();
    filter_switch_count=0;
    filter_macro_count=0;

    //
    // Open Database
    //
    QString err(tr("sas_filter: "));
    filter_db=RDInitDb (&err);
    if(!filter_db) {
        fprintf(stderr,"%s\n",err.ascii());
        exit(1);
    }

    //
    // RIPCD Connection
    //
    filter_ripc=new RDRipc("");
    filter_ripc->connectHost("localhost",RIPCD_TCP_PORT,rd_config->password());

    //
    // Station Configuration
    //
    filter_rdstation=new RDStation(rd_config->stationName());

    //
    // RDCatchd Connection
    //
    filter_connect=new RDCatchConnect(0,this,"filter_connect");
    filter_connect->connectHost("localhost",RDCATCHD_TCP_PORT,
                                rd_config->password());

    //
    // Read Switches
    //
    if((qApp->argc()==2)&&(!strcmp(qApp->argv()[1],"-d"))) {   // Delete List
        DeleteList();
        filter_connect->reset();
        exit(0);
    }
    if((qApp->argc()==3)&&(!strcmp(qApp->argv()[1],"-i"))) {   // Insert List
        InsertList();
        filter_connect->reset();
        exit(0);
    }
    fprintf(stderr,"\nsas_filter %s\n",SAS_FILTER_USAGE);
    exit(1);
}
Exemple #17
0
int main() {
	LNode* list = 0;
	InitLkList(list);
	InsertList(list,1, 30.0);
	InsertList(list, 1, 40.0);
	InsertList(list, 1, 50.0);
	InsertList(list, 1, 60.0);

	OutList(list);

	DeleteList(list,2);
	OutList(list);

	SetElem(list, 2, 78.56);
	OutList(list);
	return 0;
}
Exemple #18
0
void Add( LinkList *&L1, LinkList *&L2)
{	LinkList *p = L2->next;
	while(p!=NULL)
	{	InsertList( L1, p->b,p->e);
		p = p->next;
	}
	//DispList(L1);
}
int main(){
    int i;
    DataType a[] = {8,10,15,21,67,91};
    DataType b[] = {5,9,10,13,21,78,91};
    LinkList A,B,C;
    ListNode *p;
    InitList(&A);
    InitList(&B);
    for(i = 1;i <= sizeof(a) / sizeof(a[0]);i++){
        if(InsertList(A,i,a[i - 1]) == 0){
            printf("a插入位置不合法\n");
            return 0;
        }
    }
    for(i = 1;i <= sizeof(b) / sizeof(b[0]);i++){
        if(InsertList(B,i,b[i - 1]) == 0){
            printf("b插入位置不合法\n");
            return 0;
        }
    }
    printf("单链表A中有%d个元素:\n",ListLength(A));
    for(i = 1;i <= ListLength(A);i++){
        p = Get(A,i);
        if(p)
            printf("%4d",p->data);
    }
    printf("\n");
    printf("单链表B中有%d个元素:\n",ListLength(B));
    for(i = 1;i <= ListLength(B);i++){
        p = Get(B,i);
        if(p)
            printf("%4d",p->data);
    }
    printf("\n");
    MergeList(A,B,&C);
    printf("单链表C中有%d个元素:\n",ListLength(C));
    for(i = 1;i <= ListLength(C);i++){
        p = Get(C,i);
        if(p)
            printf("%4d",p->data);
    }
    printf("\n");
    return 0;
}
/***************************************************************************
*									   *
* FUNCTION:	CopyList						   *
*									   *
*  PURPOSE:	Create a Copy of an entire List.			   *
*									   *
*   PARAMS:	The list to copy;					   *
*									   *
*   RETURN:	A new list containing the copy if successful.		   *
*		NULL else.						   *
*									   *
*  IMPORTS:	TailList, NextList, InsertList				   *
*									   *
*    NOTES:	Because Lists contains only pointers only them are	   *
*		duplicated! The objects they refers are not copied.	   *
*									   *
*		In LIFO and FIFO lists in head are the older elements, so  *
*		if we insert in NewL from head to tail the object order    *
*		is preserved.						   *
*									   *
*   10/11/92	Added  for(i=0;... to manage circular Lists		   *
*									   *
***************************************************************************/
List CopyList(List l)
{
 List NewL;
 pointer object;

 if(!l) ErrorNULL("CopyList, not initialized List.\n");

 NewL=(List)malloc(sizeof(struct Listtag));
 NewL->objectsize=l->objectsize;
 NewL->nobject=0;
 NewL->H=NULL;
 NewL->T=NULL;
 NewL->C=NULL;
 NewL->EqualObj=l->EqualObj;
 NewL->CompareObj=l->CompareObj;
 NewL->type=l->type;
 NewL->hash=NULL;

 if(l->type!=CIRCULAR)
  {
   PushCurrList(l);

   for(HeadList(l);PrevList(&object,l);)
      InsertList(object, NewL);

   PopCurrList(l);
  }
 else
  {
   int i,n;
   n=l->nobject;
   PushCurrList(l);
   HeadList(l);
   for(i=0;i<n;i++)
    {
     PrevList(&object,l);
     InsertList(object, NewL);
    }

   PopCurrList(l);
  }
 return NewL;
}
/***************************************************************************
*									   *
* FUNCTION:	AppendList						   *
*									   *
*  PURPOSE:	Append a list to another one.				   *
*									   *
*   PARAMS:	The two lists to append.				   *
*									   *
*   RETURN:	The first list modified if successful.			   *
*		NULL else.						   *
*									   *
*  IMPORTS:	None							   *
*									   *
*    NOTES:	This function modify the first of lists passed,	appending  *
*		all the object of second list. It is assumed that the two  *
*		lists contain object of the same type.			   *
*		All the objects in L2 are inserted (if not presents) in L1.*
*									   *
***************************************************************************/
List AppendList(List L1, List L2)
{
 pointer object;

 if(!L1 || !L2) ErrorNULL("AppendList, not initialized List.\n");

 PushCurrList(L2);
 TailList(L2);
 while(NextList(&object, L2))
	if(!MemberList(object, L1)) InsertList(object, L2);
 PopCurrList(L2);
 return L1;
}
List UnionList(List L0, List L1)
{
 List UList;
 pointer object;

 if(!L0 || !L1) ErrorNULL("UnionList, not initialized List.\n");

 UList=CopyList(L0);

 TailList(L1);
 while(NextList(&object, L1))
	if(!MemberList(object, UList)) InsertList(object, UList);

 return UList;
}
Exemple #23
0
int main(int argc, const char *argv[])
{
  Node* head = CreateList();
  int v = 5;
  InsertList(head, v);
  InsertList(head, v);
  InsertList(head, v);
  v = 10;
  int i = InsertList(head, v, 4);
  v = 20;
  i = InsertList(head, v, 4);
  v = 1;
  i = InsertList(head, v);
  printf("i:%d\n", i);
  PList(head);
  printf("\n\n");
  PListRecurse(head->next);

  printf("\nreserve list:\n");
  ReserveList(head);
  PList(head);
  printf("\n---- reserve list\n");

  Node* p = GetNode(head, 1);
  if( NULL != p )
  {
    printf("\n0 node d:%d p:%016lX\n", p->d, reinterpret_cast<uint64_t>(p));
  }

  Node* head2 = CreateList();
  head2->next = p;
  printf("\nlist2\n");
  PList(head2);
  printf("\n");

  int retInterSection = CheckUnion(head, head2);
  printf("checkunion ret:%d\n", retInterSection);

  int ret = CheckCircle(head);
  printf("check circle:%d\n", ret);

  printf("makecircle \n");
  MakeCircle(head);
  //PList(head);

  retInterSection = CheckUnion(head, head2);
  printf("checkunion2 ret:%d\n", retInterSection);

  ret = CheckCircle(head);
  printf("check circle:%d\n", ret);

  i = FindInList(head, 20);
  printf("\nfind i:%d\n", i);
  
  return 0;
}
Exemple #24
0
void  Recover(int start, int end)  {
	LN *p,*t;
	int size,flag=0;
	size=end-start;	
	p=L->next;
	t=p->next;
	while(p){
		if(t && p->end==start && t->start==end){
			p->size = p->size + size + t->size;
			p->end = t->end;
			p->next=t->next;
            t->next->front=p;
			free(t);
			n--;
			SortList();			
			
			flag=1;
            break;			
		}
		else if(p->end == start){    
			flag=1;
			p->size = p->size + size;
			p->end = p->end + size ;
			SortList();			
			
			break;
		}
		else if( p->start == end){
			p->size= p->size +size;
			p->start=start;
			SortList();
			flag=1;
			
			break;
		}
		p=p->next;     
		if(p)
			t=p->next;               
	}

	if(flag==0){ 
		InsertList(size,start); 
		n++;
	}
	printf("回收后的空闲链表情况如下:");
	PrintList();  
	printf("按任意键继续\n");  
}
Exemple #25
0
void main()
{
    struct sqlist *sq;
    int i, n, t;
    sq = (struct sqlist *)malloc(sizeof(struct sqlist));
    sq->length = 0;
    printf("please input the size of link:\n");
    for (i = 0; i < n; i++){
        scanf("%d", &t);
        InsertList(sq, t, i);
    }
    printf("now the link is :\n");
    for (i = 0; i < sq->length; i++){
        printf("%d", sq->data[i]);
    }
    getch();
}
Exemple #26
0
void GetFree()  {
	int size,start,i;
	L=getpch(LN);  
	L->next=NULL;
	L->front=NULL;
	printf("请输入空闲区数:");
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{	
		printf("请输入第%2d空闲区的大小和始址:\n",i);
		scanf("%d %d",&size,&start);
		InsertList(size,start);
	}
	printf("分配完毕!\n");
	//printf("\n空闲链表情况:\n");
	//PrintList();
}
Exemple #27
0
int main(){
    struct Seqlist s;
    int i=0,k;
    Initlist(&s);
    printf("input data: ");
    do{
        scanf("%d",&k);
        if(k==0) break;
        InsertList(&s,k,i);
        printf("%d ",s.data[i++]);
    }while(1);
    printf("\n");
    printf("delete element: \n");
    scanf("%d",&k);
    DeleteList(&s,k);
    printf("output sequeue list: \n");
    for(i=0;i<ListSize-1;i++){
        printf("%d ",s.data[i]);
    }
}
Exemple #28
0
/**
* @brief main \n
* 测试程序的主函数,进行int以及char的创建、增、删、改、查、排序、清空操作。
* @param[in]	argc		带int参数形式
* @param[in]	*argv[]		带char参数形式
* @return		函数默认返回值
*/
int main( int argc, char *argv[] )
{
	DLNode *List;
	/* 进行int 数组测试 */
	int num[1000],i = 0;
	for(i = 0; i < 1000; i++)
	{
		//srand(time(NULL));
		num[i] = rand();
	}
	List = CreateList();
	if (List == NULL)
		printf("Error!\n");
	else
		printf("OK!Create OK!\n");
	for(i = 0; i < 1000; i++)
		InsertList(List,(void *)&num[i]);//(num + i));
	ShowList(List,0);
	sleep(1);
	SequenceList(List,0,CallBackSequence);
	ShowList(List,0);
	sleep(1);
	SearchList(List,&num[1],0,CallBackSearch);
	UpdateList(List,&num[1],&num[5],0);
	ShowList(List,0);
	sleep(1);
	DeleteList(List,&num[5],0);
	ShowList(List,0);
	sleep(1);
	DropList(List);
	ShowList(List,0);
	sleep(1);
	/* 进行char * 字符串测试 */
	char *test1 = "test1";
	char *test2 = "test2";
	char *test3 = "test3";
	char *test5 = "test5";
	List = CreateList();
	if (List == NULL)
		printf("Error!\n");
	else
		printf("OK!Create OK!\n");
	InsertList(List,test1);
	InsertList(List,test2);
	InsertList(List,test3);
	ShowList(List,2);
	sleep(1);
	SequenceList(List,2,CallBackSequence);
	SearchList(List,test2,2,CallBackSearch);
	UpdateList(List,test1,test5,2);
	ShowList(List,2);
	sleep(1);
	DeleteList(List,test5,2);
	ShowList(List,2);
	sleep(1);
	DropList(List);
	ShowList(List,2);
	sleep(1);
	/* 进行char 字符测试 */
	char ch[1000];
	int chascii;
	for(i = 0; i< 1000; i++)
	{
		//srand(time(NULL));
		chascii = rand()%25; //生成0-25的值
		ch[i] = chascii + 'a';
	}
	for(i = 0; i < 1000; i++)
		InsertList(List,(void *)&ch[i]);//(num + i));
	ShowList(List,1);
	sleep(1);
	SequenceList(List,1,CallBackSequence);
	ShowList(List,1);
	sleep(1);
	SearchList(List,&ch[1],1,CallBackSearch);
	UpdateList(List,&ch[1],&ch[5],1);
	ShowList(List,1);
	sleep(1);
	DeleteList(List,&ch[5],1);
	ShowList(List,1);
	sleep(1);
	DropList(List);
	ShowList(List,1);
	
	return 0;
}
void DeWall(Point3 *v[], Point3 *BaseV, int *UsedPoint, int n, List Q, List T, enum Axis a)
{
 List Ln=NULL_LIST,
      La=NULL_LIST,
      Lp=NULL_LIST;

 Tetra *t;
 ShortTetra *st;
 Face  *f;
 int i,j;
 UG g;
 Plane alpha;

 alpha.N.x=0;
 alpha.N.y=0;
 alpha.N.z=0;
 alpha.off=0;

 if(n>20)
 if(UGScaleFlag) BuildUG(v,UsedPoint,n, (int)(n*UGScale),&g); 	/* Initialize Uniform Grid */
	   else BuildUG(v,UsedPoint,n,      n,&g);

 Ln=NewList(FIFO,sizeof(Face));			/* Initialize Active Face */
 ChangeEqualObjectList(EqualFace,Ln);		/* List Ln.		  */
 if(n>40) HashList(n/4,HashFace,Ln);

 La=NewList(FIFO,sizeof(Face));			/* Initialize Active Face */
 ChangeEqualObjectList(EqualFace,La);		/* List La.		  */
 if(n>40) HashList(n/4,HashFace,La);

 Lp=NewList(FIFO,sizeof(Face));			/* Initialize Active Face */
 ChangeEqualObjectList(EqualFace,Lp);		/* List Lp.		  */
 if(n>40) HashList(n/4,HashFace,Lp);


 switch(a)
  {
   case XAxis :	qsort((void *)v, (size_t)n, sizeof(Point3 *),
				 (int (*)(const void *,const void *))XComp);
		alpha.N.x = 1;
		alpha.off = (v[n/2-1]->x+v[n/2]->x)/2;
		break;

   case YAxis : qsort((void *)v, (size_t)n, sizeof(Point3 *), 
				 (int (*)(const void *,const void *))YComp);
		alpha.N.y = 1;
		alpha.off = (v[n/2-1]->y+v[n/2]->y)/2;
		break;

   case ZAxis : qsort((void *)v, (size_t)n, sizeof(Point3 *),
				 (int (*)(const void *,const void *))ZComp);
		alpha.N.z = 1;
		alpha.off = (v[n/2-1]->z+v[n/2]->z)/2;
		break;
  }

 if(CountList(Q)==0)
 {
  t=FirstTetra(v,n);

  for(i=0;i<4;i++)
    {
      switch (Intersect(t->f[i],&alpha))
	{
	case  0 :     InsertList(t->f[i], La);	 break;
	case  1 :     InsertList(t->f[i], Lp);	 break;
	case -1 :     InsertList(t->f[i], Ln);	 break;
	}
      for(j=0;j<3;j++)
	if(t->f[i]->v[j]->mark==-1)  t->f[i]->v[j]->mark=1;
	else t->f[i]->v[j]->mark++;
    }
  st=Tetra2ShortTetra(t,BaseV);
  free(t);
  InsertList(st,T);
  SI.Face+=4;
 }
 else
 {
  while(ExtractList(&f,Q))
    switch (Intersect(f,&alpha))
    {
      case  0 :     InsertList(f, La);	 break;
      case  1 :     InsertList(f, Lp);	 break;
      case -1 :     InsertList(f, Ln);	 break;
    }
 }

 while(ExtractList(&f,La))
 {
  if(n>20) t=FastMakeTetra(f,v,n,&g);
      else t=MakeTetra(f,v,n);
  if(t==NULL) SI.CHFace++;
  else
     {
      st=Tetra2ShortTetra(t,BaseV);

      if(SafeTetraFlag) if(MemberList(st, T))
			Error("Cyclic Tetrahedra Creation\n",EXIT);
      InsertList(st,T);

      SI.Face+=3;
      SI.Tetra++;

      if(UpdateFlag)
	 if(SI.Tetra%50 == 0) printf("Tetrahedra Built %i\r",SI.Tetra++);

      for(i=1;i<4;i++)
	 switch (Intersect(t->f[i],&alpha))
	  {
	   case	0 :	if(MemberList(t->f[i],La))
			  {
			   DeleteCurrList(La);
			   
			   SI.Face--;
			   for(j=0;j<3;j++)
			     t->f[i]->v[j]->mark--;
			   free(t->f[i]);
			  }
			else 
			  {
			    InsertList(t->f[i],La);
			    for(j=0;j<3;j++)
			      if(t->f[i]->v[j]->mark==-1)  t->f[i]->v[j]->mark=1;
			      else t->f[i]->v[j]->mark++;
			    
			  }
	     break;
	   case 1 :	if(MemberList(t->f[i],Lp))
			  {
			    DeleteCurrList(Lp);
			  
			    SI.Face--;
			    for(j=0;j<3;j++)
			      t->f[i]->v[j]->mark--;
			    free(t->f[i]);
			  }
	                else 
			  {
			    InsertList(t->f[i],Lp);
			    for(j=0;j<3;j++)
			      if(t->f[i]->v[j]->mark==-1)  t->f[i]->v[j]->mark=1;
			      else t->f[i]->v[j]->mark++;
			    
			  }
	     break;
	   case -1:	if(MemberList(t->f[i],Ln))
			  {
			    DeleteCurrList(Ln);
	
			    SI.Face--;
			    for(j=0;j<3;j++)
			      t->f[i]->v[j]->mark--;		
			    free(t->f[i]);

			  }
			else 
			  {
			    InsertList(t->f[i],Ln);
			    for(j=0;j<3;j++)
			      if(t->f[i]->v[j]->mark==-1)  t->f[i]->v[j]->mark=1;
			      else t->f[i]->v[j]->mark++;
			    
			  }
			break;
	  }

      free(t->f[0]);
      free(t);
     }
  free(f);
 }
 if(SI.WallSize==0) SI.WallSize=SI.Tetra;
 /* if(n>20) EraseUG(&g); */ 

 switch(a)
  {
   case XAxis : if(CountList(Ln)>0) DeWall(v,	     BaseV,UsedPoint,n/2,    Ln,T,YAxis);
		if(CountList(Lp)>0) DeWall(&(v[n/2]),BaseV,UsedPoint,n-(n/2),Lp,T,YAxis);
		break;
   case YAxis : if(CountList(Ln)>0) DeWall(v,	     BaseV,UsedPoint,n/2,    Ln,T,ZAxis);
		if(CountList(Lp)>0) DeWall(&(v[n/2]),BaseV,UsedPoint,n-(n/2),Lp,T,ZAxis);
		break;
   case ZAxis : if(CountList(Ln)>0) DeWall(v,	     BaseV,UsedPoint,n/2,    Ln,T,XAxis);
		if(CountList(Lp)>0) DeWall(&(v[n/2]),BaseV,UsedPoint,n-(n/2),Lp,T,XAxis);
		break;
  }

 EraseList(Ln);
 EraseList(La);
 EraseList(Lp);
}
Exemple #30
0
static struct _ListNode *Transfer_lyric(const u8 *lrc_buff, size_t size, Node *first)
//int Transfer_lyric()
{
	LrcData data[DATALEN];
	LrcData *p_data = data;
	char lyric_buff[DATALEN];
	char *q = lyric_buff;
	int offset;
	float time[TIMECOUNT][TIME];
//	Node *first = NULL;

	char test[1000] = "   [ti:Shape Of My Heart]\n"
			"[ar:Backstreet Boys]\n"
			"[al:Black And Blue]\n"
			"[by:[email protected]]\n"
			"[offset:500]\n"
//			"[00:03.00]\n"
//			"\n"
			"  [00:04.10]Hmm, yeah, yeah\n"
			"[00:09.80]Baby, please try to forgive me\n"
			"[00:19.50]Stay here don't put out the glow\n"
			"[00:29.17]Hold me now don't bother\n"
//			"[03:11.45][02:51.90][01:48.00][00:47.29]Lookin' back on the things I've done\n"
//			"[03:14.70][02:55.50][01:52.70][00:52.04]I was tryin' to be someone\n"
//			"[03:19.15][02:59.70][01:57.00][00:56.44]I played my part, kept you in the dark\n"
			"[03:24.53][03:05.40][02:47.29][02:02.33][01:01.74]Now let me show you the shape of my heart";
	u8 *p = test;



	while (*p) {
		int flag = 0;
		memset(time, 0, TIMECOUNT * TIME);
		q = lyric_buff;

		while (*p != '\n' && *p) {
			if (*p == '[') {
				p++;
				if (NISNUM(*p)) {
					head_parse(p, &offset);
					continue;
				} else {
					flag += 1;
					while (*p != ':')
						time[flag - 1][0] = time[flag - 1][0] * 10  + (*p++ - '0');

					while (*++p != '.')
						time[flag - 1][1] = time[flag - 1][1] * 10 + (*p - '0');

					while (*++p != ']')
						time[flag - 1][2] = time[flag - 1][2] * 10 + (*p - '0');
				}
			}

			if (*++p != '[' && *p != ' ') {
				while (*p) {
					if (*p == '\n')
						break;
					*q++ = *p++;
				}
				*q = '\0';

				while (flag--) {
					//p_data->str = malloc(512);

					strcpy(p_data->str, lyric_buff);
					p_data->time = time[flag][0] * 60 + time[flag][1] + (time[flag][2] + offset) / 1000 ;

//					printf("%f  ",p_data->time);
//					printf("%s\n",p_data->str);
					first = InsertList(first, *p_data);
					//p_data++;
				}
			}
		}
		p++;
	}

	traverselist(first);
	return first;
}