Beispiel #1
0
/*
 * Sets an active tag array from the 'list' string.
 * An empty 'list' sets the array to contain nothing, but a NULL list sets
 * the array to the default - all.
 */
int SetActiveTags2 (char *list, int *num, char ***types) {
    if (*types)
	Tcl_Free((char *)*types);
 
    if (list) {
	if (SplitList(list, num, types) == -1) {
	    *types = NULL;
	    *num = 0;
	    return -1;
	}
    } else {
	int i;

	if (NULL == (*types = (char **)Tcl_Alloc(tag_db_count * sizeof(char *)))){
	    *num = 0;
	    return -1;
	}

	for (i = 0; i < tag_db_count; i++) {
	    (*types)[i] = tag_db[i].id;
	}
	*num = tag_db_count;
    }

    return 0;
}
Beispiel #2
0
void CInPlaceList::UpdateText(const CString& text)
{
    Strings strings;
    SplitList(text, L"=", strings);

    CString val = (strings.size() == 2)
                  ? strings[0] : text;

    SetWindowText(val);
}
Beispiel #3
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;
}
////////////////////////////////////////////////////////////////////////////////
//
//   Name:          MergeSort
//
//   Type:          Function
//
//   Description:   To do a merge sort
//
//   Inputs:        pThisNode -  the head of the list to be sorted
//                  start - the starting index
//                  finish - the end index
//                  Dir - sort ascending or descending
//
//   Outputs:       void
//
////////////////////////////////////////////////////////////////////////////////
P_Node MergeSort (NodeFunctions *LLFunctions, P_Node pThisNode, int start, int finish, unsigned char Dir)
{
    P_Node pTempNode = NULL;

    if (pThisNode == NULL)
        return pTempNode;

    if (start >= finish)
        return pThisNode;

    pTempNode = SplitList(pThisNode,start,finish/2);

    if (finish - start == 1)
        return Merge(LLFunctions,pTempNode,pThisNode,Dir);

    return Merge(LLFunctions,
				MergeSort(LLFunctions,pThisNode,start,finish/2, Dir),
                MergeSort(LLFunctions,pTempNode,(finish/2) + 1,finish, Dir),
                Dir);
}
void MergeSortOnLL( ListNode **headRef )
{
	// If 0 or 1 elements in the input list, return from here.
	if( !(*headRef) || !(*headRef)->next )
		return;

	ListNode* a = NULL;

	SplitList( (*headRef), &a );

	ListNode *temp = a->next;
	a->next = NULL;
	
	MergeSortOnLL( headRef );
	MergeSortOnLL( &temp );

	ListNode *result = NULL;
	MergeLists( *headRef, temp, &result );

	*headRef = result;
}
Beispiel #6
0
/* do_chanset() set (options) on (chan)
 * USES DO_LOCAL|DO_NET bits.
 */
int do_chanset(char *result, struct chanset_t *chan, const char *options, int flags)
{
  int ret = OK;

  if (flags & DO_NET) {
    size_t bufsiz = 0;
         /* malloc(options,chan,'cset ',' ',+ 1) */
    if (chan)
      bufsiz = strlen(options) + strlen(chan->dname) + 5 + 1 + 1;
    else
      bufsiz = strlen(options) + 1 + 5 + 1 + 1;
    
    char *buf = (char*) my_calloc(1, bufsiz);

    strlcat(buf, "cset ", bufsiz);
    if (chan)
      strlcat(buf, chan->dname, bufsiz);
    else
      strlcat(buf, "*", bufsiz);
    strlcat(buf, " ", bufsiz);
    strlcat(buf, options, bufsiz);
    putlog(LOG_DEBUG, "*", "sending out cset: %s", buf);
    putallbots(buf); 
    free(buf);
  }

  if (flags & DO_LOCAL) {
    bool cmd = (flags & CMD);
    struct chanset_t *ch = NULL;
    int all = chan ? 0 : 1;

    if (chan)
      ch = chan;
    else
      ch = chanset_default; //First iteration changes default, then move on to all chans

    while (ch) {
      const char **item = NULL;
      int items = 0;

      if (SplitList(result, options, &items, &item) == OK) {
        ret = channel_modify(result, ch, items, (char **) item, cmd);
      } else 
        ret = ERROR;


      free(item);

      if (all) {
        if (ret == ERROR) /* just bail if there was an error, no sense in trying more */
          return ret;

        if (ch == chanset_default)
          ch = chanset;
        else
          ch = ch->next;
      } else {
        ch = NULL;
      }
    }
  }
  return ret;
}