コード例 #1
0
int main(int argc, char **argv)
{
    int i;
    int n;
    NodePtr node;
    JobPtr job;
    ListPtr list;

    if (argc != 2) {
        fprintf(stderr, "Usage: %s <list size> \n",argv[0]);
        exit(1);
    }
    n = atoi(argv[1]);

    list = createList();
    for (i=0; i<n; i++) {
        job = createJob(i, "cmd args");
        node = createNode(job);
        addAtFront(list, node);
    }

    printList(list);
    reverseList(list);
    printList(list);
    reverseList(list);
    printList(list);

    exit(0);
}
コード例 #2
0
ファイル: List.c プロジェクト: chilininsd/bridge
ListPtr restoreList(char *saveFile)
{
	int size;
	FILE *fin;
	ListPtr list;
	NodePtr node;
	char errmsg[MAX_MSG_LENGTH];

	if (saveFile == NULL) return NULL;
	if (strlen(saveFile) == 0) return NULL;
	fin = fopen(saveFile, "r");
	if (!fin) {
		sprintf(errmsg, "restoreList: %s",saveFile);
		perror(errmsg);
		return NULL;
	}

	fread(&size, sizeof(int), 1, fin);
	if (size <= 0) return NULL;
	printf("restore: list size = %d\n", size);
	list = createList();

	while (size > 0) {
		node = restoreNode(fin);
		addAtFront(list, node);
		size--;
	}

	fclose(fin);
	return list;
}
コード例 #3
0
ファイル: SimpleTest.c プロジェクト: sylsr/CS253-lab
int main(int argc, char **argv)
{
	int i;
	int n;
	struct node *list;
	struct node *node;

	if (argc != 2) {
		fprintf(stderr, "Usage: %s <list size> \n",argv[0]);
		exit(1);
	}
	n = atoi(argv[1]);

	list = NULL;
	for (i=0; i<n; i++) {
		node = (struct node*) malloc(sizeof(struct node));
		if (node == NULL) {
			printf("Error allocating node for linked list\n");
			exit(1);
		}
		node->item = i;
		list = addAtFront(list, node);
	}

	printList(list);

	list=reverseList(list);
	printList(list);

	return 0;
}
コード例 #4
0
ファイル: TestSuiteChkPt.c プロジェクト: chilininsd/bridge
int main(int argc, char **argv)
{	
	int i;

	NodePtr node;
	JobPtr job;
	ListPtr list;

	process_cmdline_arguments(argc, argv);

	if (state->restart) {
			fprintf(stderr, "%s: Attempting to restart from checkpoint.\n", program);
			list = start_from_checkpoint();
	} else {
		list = createList();
		for (i=0; i<state->n; i++)
		{
			job = createJob(i, "args");
			node = createNode(job);
			addAtFront(list, node);
		}
	}

	runRandomTests(state, list);

	if (DEBUG > 0)
		printList(list);

	remove(stateFile);
	remove(state->saveFile);
	exit(0);
}
コード例 #5
0
ファイル: UnitTestList.c プロジェクト: Shanepruett/CS453Lab5
Boolean addAtFrontWithNoNodes()
{
	NodePtr node = createTestNode(1);

	addAtFront(testlist, node);

	myassert(testlist->size == 1)
	myassert(testlist->head == node)
	myassert(testlist->tail == node)
	myassert(testlist->head->next == NULL)
	myassert(testlist->head->prev == NULL)

	return TRUE;
}
コード例 #6
0
ファイル: TestList.c プロジェクト: thomascampbelladams/dash
/**
* Runs tests on the addAtFront function
**/
void addAtFrontTest(ListPtr list, int count)
{
	int i;
	for(i = 0; i < count; i++)
	{
		char str[80];
		sprintf(str, "%s: %d", "Job", i);
		JobPtr job = createJob(i, str, i);
		NodePtr node = createNode(job);
		addAtFront(list, node);
	}
	if(DEBUG > 0)
		verifyAddAtFrontList(list, count);
}
コード例 #7
0
ファイル: SimpleTestList.c プロジェクト: kgross99/count
int main(int argc, char **argv) {
	int i;
	int n;
	NodePtr node;
	WordObjPtr job;
	ListPtr list;

	if (argc != 2) {
		fprintf(stderr, "Usage: %s <list size> \n", argv[0]);
		exit(1);
	}
	n = atoi(argv[1]);

	list = createList((void *) compareTo, (void *)toString,(void *)freeWordObj);
	for (i = 0; i < n; i++) {
		char str[25];
				sprintf(str, "%d", i);
		job = createWordObj(str,1);
		node = createNode((void *)job);
		addAtFront(list, node);
	}
	job=createWordObj("hi",1);
	search(list, job);
	printf("searched\p");

	printList(list);


	reverseList(list);
	printList(list);

	reverseList(list);

	printList(list);


	freeList(list);

	exit(0);
}
コード例 #8
0
int main(int argc, char **argv)
{	
  int i;
  int n;
  int count;
  unsigned int seed=0;

  ObjectPtr job;
  NodePtr node;
  ListPtr list;

  if (argc < 2) {
    fprintf(stderr, "Usage: %s <list size> [<test size=list size>] [<seed>] \n",argv[0]);
    exit(1);
  }
  n = atoi(argv[1]);
  count = n;
  if (argc >=  3) {
    count = atoi(argv[2]);
  }
  if (argc == 4) {
    seed = atoi(argv[3]);
  }

  list = createList(compareTo, toString, freeObject);
  for (i=0; i<n; i++)
    {
      job = createObject(i, "args");
      node = createNode(job);
      addAtFront(list, node);
    }

  runRandomTests(count, seed, n, list);

  if (DEBUG_LEVEL > 0)
    printList(list);

  freeList(list);
  exit(0);
}
コード例 #9
0
void SummerList<Type> :: addAtIndex(int index, Type data)
{
    assert(index>=0 && index <= size);
    //different from array- we can add to the end
    
    DataNode<Type> *indexPointer = front;
    
    //create a node below
    DataNode<Type> *newNode = new DataNode<Type>(data);//newNode is the address- it is a pointer,it makes a new dataNode and a new Pointer
    
    if(index == 0)
    {
        addAtFront(data);
 
    }
    else if(index == size - 1)
    {
        add(data);

    }
    else
    {
        for(int position = 0; position < index - 1; position++)
        {
            indexPointer = indexPointer->getNodePointer();
        }//get to the spot before the spot i am adding
        
        
        
        DataNode<Type> *temp = indexPointer->getNodePointer();
        newNode->setNodePointer(temp);
        
        indexPointer->setNodePointer(newNode);
        //setting indexPointer to point to newNode address
        
        size++;
  
    }
}
コード例 #10
0
ファイル: SaveList.c プロジェクト: KelsonBall/CS253-resources
int main(int argc, char **argv)
{
    int i;
    int n;
    NodePtr node;
    JobPtr job;
    ListPtr list;
    char *saveFile;

    if (argc < 2) {
        fprintf(stderr, "Usage: %s <list size> [<checkpoint file>] \n",argv[0]);
        exit(1);
    }
    n = atoi(argv[1]);
    saveFile = NULL;
    if (argc == 3) {
        saveFile = argv[2];
    }

    list = createList();
    for (i=0; i<n; i++) {
        job = createJob(i, "cmd args");
        node = createNode(job);
        addAtFront(list, node);
    }

    if (!saveFile) printList(list);
    printList(list);

    if (saveFile) {
        printf("checkpointing to file %s\n", saveFile);
        checkpointList(list, saveFile);
    }

    exit(0);
}
コード例 #11
0
ファイル: TestSuiteChkPt.c プロジェクト: chilininsd/bridge
void runRandomTests(struct parameters *state, ListPtr list)
{
	int i;
	int start;
	int test;
	NodePtr node;
	JobPtr job;
	long int num;

   	srand(state->seed);
	start=0;
	if (state->restart) {
		start = state->done+1;
		srand(state->randomNum);
	}
    for (i=start; i<state->count; i++) {
		num = rand();
        test = num % NUM_TESTS;
		if ((i > 0) && ((i % CHECKPOINT_COUNT) == 0)) {
			fprintf(stderr, "checkpointing list, count = %d\n", i);
			state->done = i-1;
			state->randomNum = num;
			checkpointList(list, state->saveFile);
			checkpointTestSuite(state, stateFile);
		}
        switch (test) {
            case 0:
				if (DEBUG > 1) fprintf(stderr,"addAtFront\n");
                state->n++;
                job = createJob(state->n, "some info");
                node = createNode(job);
                addAtFront(list, node);
                break;
            case 1:
				if (DEBUG > 1) fprintf(stderr,"addAtRear\n");
                state->n++;
                job = createJob(state->n, "some info");
                node = createNode(job);
                addAtRear(list, node);
                break;
            case 2:
				if (DEBUG > 1) fprintf(stderr,"removeFront\n");
                node = removeFront(list);
                break;
            case 3:
				if (DEBUG > 1) fprintf(stderr,"removeRear\n");
                node = removeRear(list);
                break;
            case 4:
				if (DEBUG > 1) fprintf(stderr,"removeNode\n");
                node = removeNode(list, search(list, i));
                break;
            case 5:
				if (DEBUG > 1) fprintf(stderr,"reverseList\n");
                reverseList(list);

            default:
                break;
        }
    }
}
コード例 #12
0
ファイル: dash.c プロジェクト: thomascampbelladams/dash
void recordCommand(NodePtr n, int jobNumber, int isBackground)
{
	printf("[%i] %i %s\n", jobNumber, n->data->jobid, n->data->command);
	addAtFront(jobList, n);
}
コード例 #13
0
void runRandomTests(int count, unsigned int seed, int n, ListPtr list)
{
  int i;
  int test;
  NodePtr node;
  ObjectPtr job;
  ObjectPtr searchJob;
  int *tests;

  tests = (int *) malloc(sizeof(int)*NUM_TESTS);
  for (i=0; i<NUM_TESTS; i++) 
    tests[i]=0;
  srandom(seed);
  for (i=0; i<count; i++) {
    test = (int) (NUM_TESTS * (double) rand()/RAND_MAX);
    tests[test]++;
    switch (test) {
    case 0:
      if (DEBUG_LEVEL > 1) fprintf(stderr,"addAtFront\n");
      n++;
      job = createObject(n, "some info");
      node = createNode(job);
      addAtFront(list, node);
      break;
    case 1:
      if (DEBUG_LEVEL > 1) fprintf(stderr,"addAtRear\n");
      n++;
      job = createObject(n, "some info");
      node = createNode(job);
      addAtRear(list, node);
      break;
    case 2:
      if (DEBUG_LEVEL > 1) fprintf(stderr,"removeFront\n");
      node = removeFront(list);
      freeNode(node, freeObject);
      break;
    case 3:
      if (DEBUG_LEVEL > 1) fprintf(stderr,"removeRear\n");
      node = removeRear(list);
      freeNode(node, freeObject);
      break;
    case 4:
      if (DEBUG_LEVEL > 1) fprintf(stderr,"removeNode\n");
      searchJob = createObject(i,"foo");
      node = removeNode(list, search(list, searchJob));
      freeNode(node, freeObject);
      freeObject(searchJob);
      break;
    case 5:
      if (DEBUG_LEVEL > 1) fprintf(stderr,"reverseList\n");
      reverseList(list);
      break;
    case 6:
      if (DEBUG_LEVEL > 1) fprintf(stderr,"searchList\n");
      searchJob = createObject(i,"foo");
      node = search(list, searchJob);
      freeObject(searchJob);
      break;
    default:
      break;
    }
  }
  print_stats(tests);
  free(tests);
}
コード例 #14
0
ファイル: TestList.c プロジェクト: thomascampbelladams/dash
/**
* Runs edge tests on the current Doubly Linked List implementation
**/
void runEdgeCases()
{
	ListPtr l = createList();
	NodePtr n = NULL;
	printf("\n%s\n%s", sep, "Running edge cases with NULL values");
	printf("\n%s", "addAtFront");
	addAtFront(NULL, NULL);
	addAtFront(l, NULL);
	addAtFront(NULL, n);
	if(l->size == 0
		&& l->head == NULL
		&& l->tail == NULL)
		printf("\nSuccess");
	else
		printf("\nFail");

	
	printf("\n%s", "addAtRear");
	addAtRear(NULL, NULL);
	addAtRear(l, NULL);
	addAtRear(NULL, n);
	if(l->size == 0
		&& l->head == NULL
		&& l->tail == NULL)
		printf("\nSuccess");
	else
		printf("\nFail");
	
	printf("\n%s", "removeFront");
	n = removeFront(NULL);
	n = removeFront(l);
	if(l->size == 0 
		&& l->head == NULL
		&& l->tail == NULL)
		printf("\nSuccess");
	else
		printf("\nFail");
	
	printf("\n%s", "removeRear");
	n = removeRear(NULL);
	n = removeRear(l);
	if(l->size == 0 
		&& l->head == NULL
		&& l->tail == NULL)
		printf("\nSuccess");
	else
		printf("\nFail");
		
	printf("\n%s", "removeNode");
	n = removeNode(NULL, NULL);
	n = removeNode(l, NULL);
	n = removeNode(NULL, n);
	if(l->size == 0 
		&& n == NULL
		&& l->head == NULL
		&& l->tail == NULL)
		printf("\nSuccess");
	else
		printf("\nFail");
		
	printf("\n%s", "reverseList");
	reverseList(NULL);
	reverseList(l);
	if(l->size == 0
		&& l->head == NULL
		&& l->tail == NULL)
		printf("\nSuccess");
	else
		printf("\nFail");
	
	printf("\n%s", "search");
	int i = 0;
	n = search(NULL, 0);
	n = search(l, 0);
	n = search(NULL, i);
	if(n == NULL)
		printf("\nSuccess");
	else
		printf("\nFail");
		
	printf("\n%s\n%s", sep, "Running edge cases with Single values");
	printf("\n%s", "addAtFront");
	JobPtr job = createJob(1, "Single", 1);
	n = createNode(job);
	l = createList();
	addAtFront(l, n);
	if(l->size == 1 
		&& l->head == n 
		&& l->tail == n 
		&& l->head->next == NULL 
		&& l->head->prev == NULL
		&& l->tail->next == NULL
		&& l->tail->prev == NULL)
		printf("\nSuccess");
	else
		printf("\nFail");
		
	printf("\n%s", "removeFront");
	NodePtr removeFrontNode = removeFront(l);
	if(l->size == 0 
		&& l->head == NULL 
		&& l->tail == NULL 
		&& removeFrontNode == n)
		printf("\nSuccess");
	else
		printf("\nFail");
		
	printf("\n%s", "addAtRear");
	addAtRear(l, n);
	if(l->size == 1 
		&& l->head == n 
		&& l->tail == n 
		&& l->head->next == NULL 
		&& l->head->prev == NULL
		&& l->tail->next == NULL
		&& l->tail->prev == NULL)
		printf("\nSuccess");
	else
		printf("\nFail");
	
	printf("\n%s s", "removeRear");
	NodePtr removeRearNode = removeRear(l);
	if(l->size == 0 
		&& l->head == NULL 
		&& l->tail == NULL 
		&& removeRearNode == n)
		printf("\nSuccess");
	else
		printf("\nFail");
		
	printf("\n%s", "removeNode, empty list");
	NodePtr testnode = removeNode(l, n);
	if(l->size == 0 
		&& l->head == NULL 
		&& l->tail == NULL 
		&& testnode == NULL)
		printf("\nSuccess");
	else
		printf("\nFail");
		
	printf("\n%s", "removeNode, one node, matches");
	addAtFront(l, n);
	testnode = removeNode(l, n);
	if(l->size == 0 
		&& l->head == NULL 
		&& l->tail == NULL 
		&& testnode == n)
		printf("\nSuccess");
	else
		printf("\nFail");
		
	printf("\n%s", "removeNode, one node, no match");
	JobPtr noMatchJob = createJob(1, "no match", 1);
	NodePtr noMatch = createNode(noMatchJob);
	addAtFront(l, noMatch);
	testnode = removeNode(l, n);
	if(l->size == 1 
		&& l->head == noMatch 
		&& l->tail == noMatch 
		&& testnode == NULL
		&& l->head->next == NULL 
		&& l->head->prev == NULL
		&& l->tail->next == NULL
		&& l->tail->prev == NULL)
		printf("\nSuccess");
	else
		printf("\nFail");
	
	printf("\n%s", "reverseList");
	reverseList(l);
	if(l->size == 1 
		&& l->head == noMatch 
		&& l->tail == noMatch 
		&& l->head->next == NULL 
		&& l->head->prev == NULL
		&& l->tail->next == NULL
		&& l->tail->prev == NULL)
		printf("\nSuccess");
	else
		printf("\nFail");
		
	printf("\n%s", "search, matches");
	testnode = search(l, 1);
	if(l->size == 1 
		&& l->head == noMatch 
		&& l->tail == noMatch 
		&& testnode == noMatch
		&& l->head->next == NULL 
		&& l->head->prev == NULL
		&& l->tail->next == NULL
		&& l->tail->prev == NULL)
		printf("\nSuccess");
	else
		printf("\nFail");
		
	printf("\n%s", "search, no match");
	testnode = search(l, 0);
	if(l->size == 1 
		&& l->head == noMatch 
		&& l->tail == noMatch 
		&& testnode == NULL
		&& l->head->next == NULL 
		&& l->head->prev == NULL
		&& l->tail->next == NULL
		&& l->tail->prev == NULL)
		printf("\nSuccess\n");
	else
		printf("\nFail\n");
		
	freeList(l);
}
コード例 #15
0
ファイル: TestList.c プロジェクト: thomascampbelladams/dash
int main(int argc, char **argv)
{	
	int i;
	int n;
	int count;
	unsigned int seed=0;

	NodePtr node;
	JobPtr job;
	ListPtr list;

	if (argc < 2) {
		fprintf(stderr, "Usage: %s <list size> [<test size=list size>] [<seed>] \n",argv[0]);
		exit(1);
	}
	n = atoi(argv[1]);
	count = n;
	if (argc >= 3) {
		count = atoi(argv[2]);
	}
	if (argc == 4) {
		seed = atoi(argv[3]);
	}

	list = createList();
	runEdgeCases();
	printf("%s\n%s\n", sep, "Running addAtFrontTest");
	addAtFrontTest(list, count);	
	
	if (DEBUG > 0)
		displayDebugInfo(list);
		
	printf("\n%s\n%s\n", sep, "Running removeFromFrontAll Test");
	removeFrontAll(list, count);

	if (DEBUG > 0)
		displayDebugInfo(list);
	
	printf("\n%s\n%s\n", sep, "Running addAtRear Test");
	addAtRearTest(list, count);
	
	if (DEBUG > 0)
		displayDebugInfo(list);
	
	printf("\n%s\n%s\n", sep, "Running removingFromRear Test");
	removeRearAll(list, count);
	
	if (DEBUG > 0)
		displayDebugInfo(list);
	//for(i = count; i > 0; i--)
		//removeFrontOne(list);
		
	printf("\n%s\n%s\n", sep, "Running removeNode Test");
	addAtRearTest(list, count);
	removeNodeAllTest(list, count);
	
	if (DEBUG > 0)
		displayDebugInfo(list);
	
	printf("\n%s\n%s\n", sep, "Running reverseList Test");
	addAtRearTest(list, count);
	reverseList(list);
	verifyAddAtFrontList(list, count);
	
	if (DEBUG > 0)
		displayDebugInfo(list);
	
	printf("\n%s\n%s\n", sep, "Running random tests");
	for (i=0; i<n; i++)
	{
		job = createJob(i, "args", i);
		node = createNode(job);
		/*printf("job ptr = %p node ptr = %p\n", job, node);*/
		addAtFront(list, node);
	}
	runRandomTests(count, seed, n, list);
	freeList(list);
	exit(0);
}