コード例 #1
0
ファイル: singly_loop.cpp プロジェクト: balabarath/MyProgs
int main()
{
    //Driver code
    struct node *head = (struct node*) malloc(sizeof(struct node));
    head->data = 0;
    head->next = NULL;
    insert(head, 6);
    insert(head, 5);
    insert(head, 4);
    insert(head, 3);
    insert(head, 2);
    insert(head, 1);
    print(head);
    head->next->next->next->next->next = head->next->next->next;
//    print(head);
//    printf("%d\n", findLoop(head)->data);
    struct node *temp = findLoopPointMethod1(head, findLoop(head));
    struct node *temp2 = findLoopPointMethod2(head, findLoop(head));
    if(temp2 == NULL)
    {
      printf("There are no loop point found");
    }
    else
    {
       printf("%d", temp->data);
    }
    scanf("%d");
    return 0;
}
コード例 #2
0
int main()
{
	node *head = (node *)malloc(sizeof(node));
	head->data = 5;
	head->next = NULL;
	node *cur =head;

	node *n1 = (node *)malloc(sizeof(node));
	n1->data = 6;
	n1->next = NULL;
	cur->next = n1;
	cur = cur->next;

	node *n2 = (node *)malloc(sizeof(node));
	n2->data = 8;
	n2->next = NULL;
	cur->next = n2;
	cur = cur->next;

	node *n3 = (node *)malloc(sizeof(node));
	n3->data = 7;
	n3->next = NULL;
	cur->next = n3;
	cur = cur->next;

	node *n4 = (node *)malloc(sizeof(node));
	n4->data = 9;
	n4->next = NULL;
	cur->next = n4;
	cur = cur->next;
	
	node *n5 = (node *)malloc(sizeof(node));
        n5->data = 19;
        n5->next = NULL;
        cur->next = n5;
        cur = cur->next;

	cur->next = n2;

	findLoop(head);
	return 0;
}
コード例 #3
0
ファイル: CTCObservable.cpp プロジェクト: benruijl/cdt
void CTCObservable::findLoop(Vertex* v, Vertex* prev) {
    if (slice.find(v) != slice.end()) {
        return;
    }

    // TODO: revert to set?
    // FIXME: does this find the same loop multiple times?
    for (unsigned int i = 0; i < loopCheck.size(); i++) {
        if (v == loopCheck[i]) {
            unsigned int overlap = 0;
            
            for (unsigned int j = i; j < loopCheck.size(); j++) {
                if (loopsVisited.find(loopCheck[j]) != loopsVisited.end()) {
                    overlap++;
                }
                
                loopsVisited.insert(loopCheck[j]);
            }
            
            if (overlap == 0) {
                ctcCount++;
            }
            
            //std::cout << "Found loop of length " << loopCheck.size() - i <<
             //       " with overlap " << overlap << std::endl;
        }
    }

    if (visited.find(v) != visited.end()) {
        return;
    }


    loopCheck.push_back(v);
    visited.insert(v); // TODO: before or after iterating neighbours?
    
    VertSet tlSector = v->getOtherSectorVertices(prev);

    foreach(Vertex* n, tlSector) {
        findLoop(n, v);
    }
コード例 #4
0
void main()
{
	int count = 0;
	struct node * temp = NULL;
	struct node * head = (struct node *)malloc(sizeof(struct node)), *new_node = head, *address = (struct node *)malloc(sizeof(struct node));
	printf("Enter the maximum numbers :");
	scanf("%d", &count);
	for (int i = 0; i < count; i++)
	{
		temp = (struct node *)malloc(sizeof(struct node));
		scanf("%d", &temp->num);
		temp->next = NULL;
		if (temp->num == 3)
			address = temp;
		head->next = temp;
		head = head->next;
	}
	head->next = address;
	int * a = findLoop(new_node->next);
	printf("Loop formed at : %d\nCorrupted node : %d", a[0],a[1]);
	_getch();
}
コード例 #5
0
ファイル: emd.cpp プロジェクト: kjarosz/cuda_udat
/**********************
    newSol
**********************/
static void newSol()
{
    int i, j, k;
    double xMin;
    int steps;
    node2_t *Loop[2*MAX_SIG_SIZE1], *CurX, *LeaveX;
 
#if DEBUG_LEVEL > 3
    printf("EnterX = (%d,%d)\n", _EnterX->i, _EnterX->j);
#endif

    /* ENTER THE NEW BASIC VARIABLE */
    i = _EnterX->i;
    j = _EnterX->j;
    _IsX[i][j] = 1;
    _EnterX->NextC = _RowsX[i];
    _EnterX->NextR = _ColsX[j];
    _EnterX->val = 0;
    _RowsX[i] = _EnterX;
    _ColsX[j] = _EnterX;

    /* FIND A CHAIN REACTION */
    steps = findLoop(Loop);

    /* FIND THE LARGEST VALUE IN THE LOOP */
    xMin = INFINITY;
    for (k=1; k < steps; k+=2)
      {
	if (Loop[k]->val < xMin)
	  {
	    LeaveX = Loop[k];
	    xMin = Loop[k]->val;
	  }
      }

    /* UPDATE THE LOOP */
    for (k=0; k < steps; k+=2)
      {
	Loop[k]->val += xMin;
	Loop[k+1]->val -= xMin;
      }

#if DEBUG_LEVEL > 3
    printf("LeaveX = (%d,%d)\n", LeaveX->i, LeaveX->j);
#endif

    /* REMOVE THE LEAVING BASIC VARIABLE */
    i = LeaveX->i;
    j = LeaveX->j;
    _IsX[i][j] = 0;
    if (_RowsX[i] == LeaveX)
      _RowsX[i] = LeaveX->NextC;
    else
      for (CurX=_RowsX[i]; CurX != NULL; CurX = CurX->NextC)
	if (CurX->NextC == LeaveX)
	  {
	    CurX->NextC = CurX->NextC->NextC;
	    break;
	  }
    if (_ColsX[j] == LeaveX)
      _ColsX[j] = LeaveX->NextR;
    else
      for (CurX=_ColsX[j]; CurX != NULL; CurX = CurX->NextR)
	if (CurX->NextR == LeaveX)
	  {
	    CurX->NextR = CurX->NextR->NextR;
	    break;
	  }

    /* SET _EnterX TO BE THE NEW EMPTY SLOT */
    _EnterX = LeaveX;
}
コード例 #6
0
void CEmdWrapper::newSol(){
    int i, j, k;
    float xMin;
    int steps;
    node2_t *Loop[2*MAX_SIG_SIZE1], *CurX, *LeaveX;
	
    /* ENTER THE NEW BASIC VARIABLE */
    i = _EnterX->i;
    j = _EnterX->j;
    _IsX[i][j] = 1;
    _EnterX->NextC = _RowsX[i];
    _EnterX->NextR = _ColsX[j];
    _EnterX->val = 0;
    _RowsX[i] = _EnterX;
    _ColsX[j] = _EnterX;
	
    /* FIND A CHAIN REACTION */
    steps = findLoop(Loop);
	
    /* FIND THE LARGEST VALUE IN THE LOOP */
    xMin = (float)EMD_INFINITY;
    for (k=1; k < steps; k+=2){
		if (Loop[k]->val < xMin){
			LeaveX = Loop[k];
			xMin = Loop[k]->val;
		}
	}
	
    /* UPDATE THE LOOP */
    for (k=0; k < steps; k+=2){
		Loop[k]->val += xMin;
		Loop[k+1]->val -= xMin;
	}
	
    /* REMOVE THE LEAVING BASIC VARIABLE */
    i = LeaveX->i;
    j = LeaveX->j;
    _IsX[i][j] = 0;
    if (_RowsX[i] == LeaveX){
		_RowsX[i] = LeaveX->NextC;
	}else{
		for (CurX=_RowsX[i]; CurX != NULL; CurX = CurX->NextC){
			if (CurX->NextC == LeaveX){
				CurX->NextC = CurX->NextC->NextC;
				break;
			}
		}
	}
	
	if (_ColsX[j] == LeaveX)
		_ColsX[j] = LeaveX->NextR;
	else{
		for (CurX=_ColsX[j]; CurX != NULL; CurX = CurX->NextR){
			if (CurX->NextR == LeaveX){
				CurX->NextR = CurX->NextR->NextR;
				break;
			}
		}
	}
	
	/* SET _EnterX TO BE THE NEW EMPTY SLOT */
	_EnterX = LeaveX;
}
コード例 #7
0
ファイル: LoopInfo.cpp プロジェクト: RSATom/Qt
bool TLoopStack::needsToReplaceSymbolWithValue(TIntermSymbol *symbol)
{
    TIntermLoop *loop = findLoop(symbol);
    return loop && loop->getUnrollFlag();
}