Example #1
0
struct ListNode * MergeList(struct ListNode *a, struct ListNode *b)
{
	struct ListNode *result = NULL;

	if (a == NULL)
	{
		/* code */
		return b;
	}
	if (b == NULL)
	{
		/* code */
		return a;
	}

	if (a->data <= b->data)
	{
		/* code */
		result = a;
		result->next = MergeList(a->next, b);
	}

	else
	{
		result = b;
		result->next = MergeList(a, b->next);
	}

	return result;
}
Example #2
0
 virtual void visitList(POETList* s) {  
    POETCode* sFirst = s->get_first(), *sRest = s->get_rest();
    POETCode* s1 = apply(sFirst);
    POETCode* s2 = (sRest == 0)? EMPTY : apply(sRest);
    if (s1 != EMPTY && s2 != EMPTY) res = MergeList(s1, s2);
    else if (s1 == EMPTY) res = s2;
    else res = s1;
 }
Example #3
0
inline void
WifiListWidget::UpdateScanResults()
{
  WifiVisibleNetwork *buffer = new WifiVisibleNetwork[networks.capacity()];
  int n = wpa_supplicant.ScanResults(buffer, networks.capacity());
  if (n >= 0)
    MergeList(buffer, n);

  delete[] buffer;
}
Example #4
0
inline void
WifiListWidget::UpdateConfigured()
{
  WifiConfiguredNetworkInfo *buffer =
    new WifiConfiguredNetworkInfo[networks.capacity()];
  int n = wpa_supplicant.ListNetworks(buffer, networks.capacity());
  if (n >= 0)
    MergeList(buffer, n);

  delete[] buffer;
}
Example #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");
}
Example #6
0
int main()
{
	int a[10]={1,2,3,4,5,6,7,8,9,10};
	//创建链表
	LinkInfo *L=CreateInfoFromArray(a,10);
	//1-单链表反转
	ReverseList(L);
	ReverseList(L);
	//2-倒数第K个的验证
	node* last[11];
	for(int i=0;i<11;i++)
		last[i]=lastK(*L,i+1);
	//3-中间元素
	node* mid=FinMid(*L);
	//4-删除无头结点
	//DelNoHead(L->head->next);
	//5-有序链表合并
	int a1[5]={5,5,4,3,1};
	int b1[3]={7,4,2};
	LinkInfo *p=CreateInfoFromArray(a1,0);//测试案例: 1-p,q 递增 2-p,q递减 3-p为空 4-q为空 5-p,q均为空
	LinkInfo *q=CreateInfoFromArray(b1,3);
	MergeList(p,q);
	//6-判断链表是否有环(并返回环的起点node*)
	LinkInfo *circle=CreateInfoFromArray(a,6);//测试:有环、无环、空链表
	node *nocross=IfCircle(circle->head);
	circle->tail->next=circle->head->next->next->next;//构造一个环
	node *cross=IfCircle(circle->head);
	//7+8-两个单链表是否相交?求交点
	LinkInfo *A=CreateInfoFromArray(a1,5);//测试:1-不交叉 2- 交叉 3- 空链表
	LinkInfo *B=CreateInfoFromArray(b1,3);
	node *nointersection1=Intersection1(A->head,B->head);
	node *nointersection2=Intersection2(A->head,B->head);//NULL
	B->tail->next=A->head->next->next->next;//设置交叉点在4
	node *intersection1=Intersection1(A->head,B->head);
	node *intersection2=Intersection1(A->head,B->head);// 4
	//9-单链表排序
	int s[10]={54,41,32,1,6,4,54,32,658,2};
	LinkInfo *linksort=CreateInfoFromArray(s,10);
	LinkSortQ(linksort,0);
	//10-删除重复元素
	DelRepeated(linksort);
	//11-拆分链表
	LinkInfo *odd=CreateLinkInfo();
	LinkInfo *even=CreateLinkInfo();
	SplitList(L,odd,even);
	//12-大整数加法
	char numa[]="-7987465413213546465461111111111";
	char numb[]="-574968465216352468749611";
	char* result=BigNum(numa,numb);
	return 0;
}
Example #7
0
inline POETCode* MergeList(POETCode* l1, POETCode* l2) {
  POETList* ll2 = dynamic_cast<POETList*>(l2);
  if (ll2 == 0 && l2 != EMPTY) {
      ll2 = ASTFactory::inst()->new_list(l2, 0);
  }

  POETList* ll1 = dynamic_cast<POETList*>(l1);
  if (ll1 != 0) {
     POETCode* ll1First=ll1->get_first(), *ll1Rest = ll1->get_rest();
     if (ll1Rest == 0) 
         return ASTFactory::inst()->new_list(ll1First, ll2); 
     return ASTFactory::inst()->new_list(ll1First, MergeList(ll1Rest, ll2)); 
  }
  return ASTFactory::inst()->new_list(l1, ll2);
}
Example #8
0
 void main()
 {
   int n=5;
   LinkList La,Lb,Lc;
   printf("按非递减顺序, ");
   CreateList2(&La,n); /* 正位序输入n个元素的值 */
   printf("La="); /* 输出链表La的内容 */
   ListTraverse(La,print);
   printf("按非递增顺序, ");
   CreateList(&Lb,n); /* 逆位序输入n个元素的值 */
   printf("Lb="); /* 输出链表Lb的内容 */
   ListTraverse(Lb,print);
   MergeList(La,&Lb,&Lc); /* 按非递减顺序归并La和Lb,得到新表Lc */
   printf("Lc="); /* 输出链表Lc的内容 */
   ListTraverse(Lc,print);
 }
vector<CCourse>* CTrackManager::BuildTrack()
{
	myTempList = new vector<CCourse>(*myCourse);
	myMorningList->clear();
	myAfternoonList->clear();
	myTotalList->clear();
	//test();

	myCounter = 0;
	GetMorningTrack();

	myCounter = 240;
	//tempList = RemoveMorningList();
	GetAfternoonTrack();
	MergeList();
	return myTotalList;
}
void main()
{
	int n = 5;
	LinkList La, Lb, Lc;

	printf("按非递减顺序,");
	CreateList1(La, n);
	printf("La=");
	ListTraverse(La, print);
	printf("按非递增顺序,");
	CreateList(Lb, n);
	printf("Lb=");
	ListTraverse(Lb, print);
	MergeList(La, Lb, Lc);
	printf("Lc=");
	ListTraverse(Lc, print);
}
Example #11
0
 void main()
 {
   SqList La,Lb,Lc;
   int j,a[4]={3,5,8,11},b[7]={2,6,8,9,11,15,20};
   InitList(La); // 创建空表La
   for(j=1;j<=4;j++) // 在表La中插入4个元素
     ListInsert(La,j,a[j-1]);
   printf("La= "); // 输出表La的内容
   ListTraverse(La,print1);
   InitList(Lb); // 创建空表Lb
   for(j=1;j<=7;j++) // 在表Lb中插入7个元素
     ListInsert(Lb,j,b[j-1]);
   printf("Lb= "); // 输出表Lb的内容
   ListTraverse(Lb,print1);
   MergeList(La,Lb,Lc);
   printf("Lc= "); // 输出表Lc的内容
   ListTraverse(Lc,print1);
 }
void main()
{
	SqList La, Lb, Lc;
	int j;
	InitList(&La); /* 创建空表La */
	for (j = 1; j <= 5; j++) /* 在表La中插入5个元素 */
		ListInsert(&La, j, j);
	printf("La= "); /* 输出表La的内容 */
	ListTraverse(La, print);
	InitList(&Lb); /* 创建空表Lb */
	for (j = 1; j <= 5; j++) /* 在表Lb中插入5个元素 */
		ListInsert(&Lb, j, 2 * j);
	printf("Lb= "); /* 输出表Lb的内容 */
	ListTraverse(Lb, print);
	MergeList(La, Lb, &Lc);
	printf("Lc= "); /* 输出表Lc的内容 */
	ListTraverse(Lc, print);
}
Example #13
0
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;
}
Example #14
0
void main()
{
    SqList La, Lb, Lc;
    int j;

    InitList(La);
    for ( j = 1; j <= 5; j++ )
        ListInsert(La, j, j);
    printf("La = ");
    ListTraverse(La, print1);

    InitList(Lb);
    for ( j = 1; j <= 5; j++ )
        ListInsert(Lb, j, j*2);
    printf("Lb = ");
    ListTraverse(Lb, print1);
    MergeList(La, Lb, Lc);
    printf("Lc = ");
    ListTraverse(Lc, print1);
}
Example #15
0
int main (int argc, char **argv) {
    Collection *List1, *List2, *NewList;

    List1       = (Collection *) malloc (sizeof (Collection));
    List1->next = NULL;
    List2       = (Collection *) malloc (sizeof (Collection));
    List2->next = NULL;

    srandom (time (NULL));

    printf      ("Original lists:\n");
    CreateList  (List1, 10);
    DispList    (List1);
    CreateList  (List2, 6);
    DispList    (List2);
    printf      ("Sorted lists:\n");
    SortList    (&List1);
    DispList    (List1);
    SortList    (&List2);
    DispList    (List2);
    NewList =   MergeList (List1, List2);
    printf      ("Merged list:\n");
    DispList    (NewList);
    DestroyList (&NewList);
    NewList =   GetIntersection (List1, List2);
    printf      ("Intersection:\n");
    DispList    (NewList);
    DestroyList (&NewList);
    NewList =   GetDiffset (List1, List2);
    printf      ("Different set:\n");
    DispList    (NewList);
    DestroyList (&NewList);

    DestroyList (&List1);
    DestroyList (&List2);
    return 0;
}
Example #16
0
static  void            *DoSortList( void *list, unsigned next_offset,
                                  bool (*before)(void *,void *),
                                  unsigned length ) {
/**************************************************************************/

    void        **array;
    void        **parray;
    void        *list2;
    unsigned    mid;
    int         i;

    if( list == NULL ) return( NULL );
    array = CGAlloc( length * sizeof( void * ) );
    if( array == NULL ) {
        mid = length / 2;
        if( mid == 0 ) return( list ); /* FATAL ERROR! */
        list2 = list;
        for( i = mid; i > 0; --i ) {
            list2 = _NEXT( list2, next_offset );
        }
        list = DoSortList( list, next_offset, before, mid );
        list2 = DoSortList( list2, next_offset, before, length - mid );
        list = MergeList( list, list2, next_offset, before );
    } else {
        list2 = list;
        parray = array;
        for( i = length; i > 0; --i ) {
            *parray++ = list2;
            list2 = _NEXT( list2, next_offset );
        }
        ShellSort( array, length, before );
        list = BuildList( array, next_offset, length );
        CGFree( array );
    }
    return( list );
}