コード例 #1
0
int main(int argc, char* argv[]){

    BinTreePtr btPtr;
    Data tempData;
    Data key;
    FILE *fp;
    NodePtr tempNode;
    char str[50];

    tempNode = malloc(sizeof(Node));

    fp = fopen("list", "r");
    if(fp == NULL)
    {
    printf("Could not open file!");
    return 1;
    }

    btPtr = initBinaryTree();

    printf("***Class Search Program***\n\n");

    while(fgets(str, 50, fp) != NULL)
    {
        if((strlen(str) > 0) && (str[strlen(str) - 1] == '\n'))
        {
            str[strlen(str) - 1] = '\0';
        }
            btPtr->root = addBST(btPtr->root, str);
    }
    printf("\nSearch for a class: ");
    fgets(str, 50, stdin);
    if((strlen(str) > 0) && (str[strlen(str) - 1] == '\n'))
    {
        str[strlen(str) - 1] = '\0';
    }

    tempNode = search_(btPtr->root, str);
    if(tempNode == NULL)
    {
        printf("\nClass not found");
    }
    else
        printf("\nYou have taken the %s course\n", tempNode->nodeData);

    printf("\nSearch for a 2nd class: ");
    fgets(str, 50, stdin);
    if((strlen(str) > 0) && (str[strlen(str) - 1] == '\n'))
    {
        str[strlen(str) - 1] = '\0';
    }

    tempNode = search_(btPtr->root, str);
    if(tempNode == NULL)
    {
        printf("\nClass not found");
    }
    else
        printf("\nYou have taken the %s course\n", tempNode->nodeData);

    printf("\nSearch for a 3rd class: ");
    fgets(str, 50, stdin);
    if((strlen(str) > 0) && (str[strlen(str) - 1] == '\n'))
    {
        str[strlen(str) - 1] = '\0';
    }

    tempNode = search_(btPtr->root, str);
    if(tempNode == NULL)
    {
        printf("\nClass not found");
    }
    else
        printf("\nYou have taken the %s course\n", tempNode->nodeData);


    inorderTraverse(btPtr->root);

    return 0;

}
コード例 #2
0
ファイル: gcvspl.cpp プロジェクト: AyMaN-GhOsT/simbody
SimTK_Real SimTK_splder_(int *ider, int *m, int *n, SimTK_Real *t, 
	const SimTK_Real *x, const SimTK_Real *c, int *l, SimTK_Real *q, int coffset)
{
    /* System generated locals */
    int i__1, i__2;
    SimTK_Real ret_val;

    /* Local variables */
    int lk1i1;
    SimTK_Real xjki;
    int i, j, k;
    SimTK_Real z;
    int i1, j1, k1, j2, m2, ii, jj, ki, jl, lk, mi, nk, lm, ml, jm,
	     ir, ju;
    extern /* Subroutine */ int search_(int *, const SimTK_Real *, SimTK_Real *,
	     int *);
    SimTK_Real tt;
    int lk1, mp1, m2m1, jin, nki, npm, lk1i, nki1;



/* ***  Derivatives of IDER.ge.2*M are alway zero */

    /* Parameter adjustments */
    
    --q;
    c -= coffset;
    --x;

    /* Function Body */
    m2 = *m << 1;
    k = m2 - *ider;
    if (k < 1) {
	ret_val = 0.;
	return ret_val;
    }

    search_(n, &x[1], t, l);

    tt = *t;
    mp1 = *m + 1;
    npm = *n + *m;
    m2m1 = m2 - 1;
    k1 = k - 1;
    nk = *n - k;
    lk = *l - k;
    lk1 = lk + 1;
    lm = *l - *m;
    jl = *l + 1;
    ju = *l + m2;
    ii = *n - m2;
    ml = -(*l);
    i__1 = ju;
    for (j = jl; j <= i__1; ++j) {
	if (j >= mp1 && j <= npm) {
	    q[j + ml] = c[coffset*(j - *m)];
	} else {
	    q[j + ml] = 0.;
	}
    }

    if (*ider > 0) {
	jl -= m2;
	ml += m2;
	i__1 = *ider;
	for (i = 1; i <= i__1; ++i) {
	    ++jl;
	    ++ii;
	    j1 = max(1,jl);
	    j2 = min(*l,ii);
	    mi = m2 - i;
	    j = j2 + 1;
	    if (j1 <= j2) {
		i__2 = j2;
		for (jin = j1; jin <= i__2; ++jin) {
		    --j;
		    jm = ml + j;
		    q[jm] = (q[jm] - q[jm - 1]) / (x[j + mi] - x[j]);
		}
	    }
	    if (jl >= 1) {
		goto L6;
	    }
	    i1 = i + 1;
	    j = ml + 1;
	    if (i1 <= ml) {
		i__2 = ml;
		for (jin = i1; jin <= i__2; ++jin) {
		    --j;
		    q[j] = -q[j - 1];
		}
	    }
L6:
	    ;
	}
	i__1 = k;
	for (j = 1; j <= i__1; ++j) {
	    q[j] = q[j + *ider];
	}
    }

    if (k1 >= 1) {
	i__1 = k1;
	for (i = 1; i <= i__1; ++i) {
	    nki = nk + i;
	    ir = k;
	    jj = *l;
	    ki = k - i;
	    nki1 = nki + 1;
	    if (*l >= nki1) {
		i__2 = *l;
		for (j = nki1; j <= i__2; ++j) {
		    q[ir] = q[ir - 1] + (tt - x[jj]) * q[ir];
		    --jj;
		    --ir;
		}
	    }
	    lk1i = lk1 + i;
	    j1 = max(1,lk1i);
	    j2 = min(*l,nki);
	    if (j1 <= j2) {
		i__2 = j2;
		for (j = j1; j <= i__2; ++j) {
		    xjki = x[jj + ki];
		    z = q[ir];
		    q[ir] = z + (xjki - tt) * (q[ir - 1] - z) / (xjki - x[jj])
			    ;
		    --ir;
		    --jj;
		}
	    }
	    if (lk1i <= 0) {
		jj = ki;
		lk1i1 = 1 - lk1i;
		i__2 = lk1i1;
		for (j = 1; j <= i__2; ++j) {
		    q[ir] += (x[jj] - tt) * q[ir - 1];
		    --jj;
		    --ir;
		}
	    }
	}
    }

    z = q[k];
    if (*ider > 0) {
	i__1 = m2m1;
	for (j = k; j <= i__1; ++j) {
	    z *= j;
	}
    }
    ret_val = z;
    return ret_val;
}