コード例 #1
0
ファイル: statistics.c プロジェクト: rishik1/reposi
/*
Function Name	:: inputData
input		:: pointer to file
return's	:: pointer to bag
This function will take in the name of the file to open. Once the file is open, read data in from the file and into the newly created bag.
 Finally return the bag.
*/
bag* inputData(char *file)
{
        FILE *fp = fopen(file,"r");
        bag *s = createBag();
        float input;

        if(fp == NULL)
        {
                printf("Error Opening file or file not found!!!\n");
                exit(0);
        }
	data *element =NULL;
 
       while(fscanf(fp,"%f",&input)!=EOF)
	{
                element = createData(input);
                addData(s,element);
		if(debug1 == 1)
		{
			printf("inputed value = %f\n",input);
        	}
	}
	if(debug1 ==1)
	{
        	printBag(s);
	}
	fclose(fp);
	return(s);
}
コード例 #2
0
ファイル: linkedListMain.c プロジェクト: marincarl/Classes
int main(int argc, char* argv[]) {
    if( argc != 2 ) return 0;

    struct bag* b = createBag();
    int n = atoi(argv[1]);/*number of elements to add*/
    int i;
    for( i = 0 ; i < n; i++)
        addToBag(b, (TYPE)i);/*Add elements*/
    double t1 = getMilliseconds();/*Time before contains()*/
    for(i=0; i<n; i++)
        containsBag(b, i);
    double t2 = getMilliseconds();/*Time after contains()*/
    printf("%d %g\n", n, t2-t1);
    return 0;
}