예제 #1
0
int main(int argc, char* argv[]){
   
   List A = newList();
   List B = newList();
   List C = NULL;
   int i;

   for(i=1; i<=20; i++){
      append(A,i);
      prepend(B,i);
   }

   printList(stdout,A); 
   printf("\n");
   printList(stdout,B); 
   printf("\n");

   for(moveFront(A); index(A)>=0; moveNext(A)){
      printf("%d ", get(A));
   }
   printf("\n");
   for(moveBack(B); index(B)>=0; movePrev(B)){
      printf("%d ", get(B));
   }
   printf("\n");

   C = copyList(A);
   printf("%s\n", equals(A,B)?"true":"false");
   printf("%s\n", equals(B,C)?"true":"false");
   printf("%s\n", equals(C,A)?"true":"false");


   moveFront(A);
   for(i=0; i<5; i++) moveNext(A); // at index 5
   insertBefore(A, -1);            // at index 6
   for(i=0; i<9; i++) moveNext(A); // at index 15
   insertAfter(A, -2);
   for(i=0; i<5; i++) movePrev(A); // at index 10
   delete(A);
   printList(stdout,A);
   printf("\n");
   printf("%d\n", length(A));
   clear(A);
   printf("%d\n", length(A));

   freeList(&A);
   freeList(&B);
   freeList(&C);

   return(0);
}
예제 #2
0
파일: Listdr.c 프로젝트: brianlin07/CMPS101
int main(){
	/*make list and output file*/
    ListHndl TheList = newList();
    FILE *out = fopen("out.out", "w");
    
    /*test empty in empty case*/
    if(isEmpty(TheList)) printf("Empty\n");
    else printf("not Empty\n");
    printf("testing insert one number\n");
    insertAtFront(TheList,(unsigned long*)25728);
    printf("%lu\n",(unsigned long)getFirst(TheList));
    printf("%lu\n",(unsigned long)getLast(TheList));
    /*should have same value*/
    
    printf("testing list with three numbers\n");
    insertAtFront(TheList,(unsigned long*)1589458);
    insertAtBack(TheList,(unsigned long*)35762111234);
    printf("%lu\n",(unsigned long)getFirst(TheList));
    
    /*test empty in full case*/
    if(isEmpty(TheList)) printf("Empty\n");
    else printf("not Empty\n");
    
	/*test moving the current pointer around*/
    moveFirst(TheList);
    moveNext(TheList);
    printf("%lu\n",(unsigned long)getCurrent(TheList));
    moveLast(TheList);
    movePrev(TheList);
    printf("%lu\n",(unsigned long)getCurrent(TheList));
    
	/*test printList*/
    printList(out, TheList);
    
	/*test makeEmpty*/
    makeEmpty(TheList);
    if(isEmpty(TheList)) printf("Empty\n");
    else printf("not Empty\n");
    
	/*test inserting functions*/
    insertAtFront(TheList,(unsigned long*)2);
    insertAtFront(TheList,(unsigned long*)1);
    insertAtFront(TheList,(unsigned long*)4);
    insertAtBack(TheList,(unsigned long*)4);
    moveLast(TheList);
    insertBeforeCurrent(TheList,(unsigned long*)3);
    printList(out,TheList);
    deleteFirst(TheList);
    deleteCurrent(TheList);
    deleteLast(TheList);
    printList(out,TheList);
    
    makeEmpty(TheList);
    printList(out,TheList);
    
	/*free list and close output file*/
    freeList(&TheList);
    fclose(out);
    return 0;
}
void GoofyLeapImageGallery::detectMovement()
{
  if(leap.getSimpleHands()[0].fingers.size() >= 4)
  {
    if(getSingleHandDetected())
    {
      ofPoint handPos = leap.getSimpleHands()[0].fingers[INDEX].tip;
      float diff = handPos.x - prevHandPos.x;
      prevHandPos = handPos;
      if(swipeFree)
      {
        if(diff > -swipeRange.y && diff < -swipeRange.x)
        {
          if(actualImageCount < urlImages.size() - 1)
            movePrev();
        }
        if(diff > swipeRange.x && diff < swipeRange.y)
        {
          if(actualImageCount > 0)
            moveNext();
        }
      }
    }
  }
}
예제 #4
0
int main() {
    ListHndl intList;
    intList = newList();

    int data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
/*
 * Integer list testing
 *
 */

    printHeading(" INTEGER LIST ", '#', 80);
    printList(stdout, intList);
    accessorTest("isEmpty", 1, isEmpty(intList));
    
    for(int i = 0; i < 10; i++) {
        insertAtFront(intList, data[i]);
        mutatorTest("%s : data = %d", "insertAtFront", data[i]);
    }

    moveFirst(intList);

    for(int i = 0; i < 5; i++) {
        printList(stdout, intList);
        insertBeforeCurrent(intList, data[i]);
        mutatorTest("insertBeforeCurrent : data = %d", data[i]);
        moveNext(intList);
    }

    accessorTest("isEmpty", 0, isEmpty(intList));
    printList(stdout, intList);

    moveFirst(intList);
    while( !offEnd(intList) ) {
        printList(stdout, intList);
        moveNext(intList);
    }

    moveLast(intList);
    while( !offEnd(intList) ) {
        printList(stdout, intList);
        movePrev(intList);
    }

    makeEmpty(intList);
    mutatorTest("makeEmpty( intList)");

    printList(stdout, intList);
    accessorTest("isEmpty", 1, isEmpty(intList));

    freeList(intList);
    return 0;
}
예제 #5
0
int main(int argc, char* argv[]){
   
   List A = newList();
   List B = newList();
   List C = NULL;
   int i;

   for(i=1; i<=20; i++){
      append(A,i);
      prepend(B,i);
   }

   printList(stdout,A); 
   printf("\n");
   printList(stdout,B); 
   printf("\n");

   for(moveTo(A,0); getIndex(A)>=0; moveNext(A)){
      printf("%d ", getElement(A));
   }
   printf("\n");
   for(moveTo(B,length(B)-1); getIndex(B)>=0; movePrev(B)){
      printf("%d ", getElement(B));
   }
   printf("\n");

   C = copyList(A);
   printf("%s\n", equals(A,B)?"true":"false");
   printf("%s\n", equals(B,C)?"true":"false");
   printf("%s\n", equals(C,A)?"true":"false");

   moveTo(A,5);
   insertBefore(A,-1);
   moveTo(A,15);
   insertAfter(A,-2);
   moveTo(A,10);
   delete(A);
   printList(stdout,A);
   printf("\n");
   clear(A);
   printf("%d\n", length(A));

   freeList(&A);
   freeList(&B);
   freeList(&C);

   return(0);
}
예제 #6
0
// moveTo()
// Moves the cursor to index i
void moveTo(List L, int i) {
	if (L == NULL) {
		printf("List Error: moveTo() called on NULL List reference\n");
		exit (1);
	}
	if (i == L->cursorIndex) return;
	if (i >= L->length || i < 0) {
		L->cursor = NULL;
		L->cursorIndex =-1;
		return;
	} if (i == 0) L->cursor = L->front;
	if (i == L->length-1) L->cursor = L->back;
	else {
		// Direction value, 0 = left, 1 = right
		int direction = 0;
		// Determine the three possible distances
		int d1 = (L->length-1) - i;
		int d2 = i;
		int d3 = abs(L->cursorIndex - i);
		// Find the shortest distance
		int min = d1;
		if (min > d2) min = d2;
		if (min > d3) min = d3;
		// Set up the traversal from the back of the list
		if (min == d1) {
			L->cursor = L->back;
			L->cursorIndex = L->length-1;
			direction = 0;
		}
		// Set up the traversal from the front of the list
		else if (min == d2) {
			L->cursor = L->front;
			L->cursorIndex = 0;
			direction = 1;
		}
		// Set up the traversal from the current cursor
		else if (min == d3) {
			if (i > L->cursorIndex) direction = 1;
		}
		// Traverse the List
		for(int j=0; j < min; j++) {
			if (direction == 1) moveNext(L);
			else movePrev(L);
		}
	}
	L->cursorIndex = i;
}
void GoofyLeapImageGallery::handGoOut()
{
  if(direction == SWIPE_RIGHT)
  {
    if(actualImageCount > 0&&abs(mainOffsetX) > maxOffsetXHandOutside)
      moveNext(transitionDuration, &easingElastic);
    else
      move(SWIPE_STOP, transitionDuration, &easingElastic);
  }
  else
  {
    if(actualImageCount < urlImages.size() - 1&&abs(mainOffsetX) > maxOffsetXHandOutside)
      movePrev(transitionDuration, &easingElastic);
    else
      move(SWIPE_STOP, transitionDuration, &easingElastic);
  }
}
int main(int argc, char * argv[]){
   int count=0;
   int u, v, index, sccNum;
   FILE *in, *out;
   char line[MAX_LEN];
   char* token;
   Graph G = NULL;
   Graph T = NULL;
   List S = newList(); // This list is our stack that determins the order of the vertices
   List R = newList();
   // check command line for correct number of arguments
   if( argc != 3 ){
      printf("Usage: %s <input file> <output file>\n", argv[0]);
      exit(1);
   }

   // open files for reading and writing 
   in = fopen(argv[1], "r");
   out = fopen(argv[2], "w");
   if( in==NULL ){
      printf("Unable to open file %s for reading\n", argv[1]);
      exit(1);
   }
   if( out==NULL ){
      printf("Unable to open file %s for writing\n", argv[2]);
      exit(1);
   }

   /* read each line of input file, then count and print tokens */
   // Assemble a graph object G using newGraph() and addArc()
   while(fgets(line, MAX_LEN, in) != NULL)  {
      count++;
	  // char *strtok(char *str, const char *delim) breaks string str into
	  // a series of tokens using the delimitrer delim. This function returns a pointer to the
	  // last token found in string. A null pointer is returned if there are no tokens left to retrieve.
      token = strtok(line, " \n");
	  
	  // int atoi(const char *str), This function returns the converted integral number as an int value.
	  // If no valid conversion could be performed, it returns zero.
	  // It converts char to int.
	  if(count == 1) {
	     // Takes in the first number as a token, sets a graph of that size
	     G = newGraph(atoi(token));
	  }
	  else {
	     // Here we want to read in both numbers
		 u = atoi(token);
		 token = strtok(NULL, " \n");
		 v = atoi(token);
		 if( u != 0 || v != 0) {
		       addArc(G, u, v);
	     }		   
         else if (u == 0 && v == 0) {
		       break;
         }			   
      } 
   }
   // Print the adjacency list representation of G to the output file
   printGraph(out, G);
   fprintf(out, "\n");
   
   // creating our Stack
   for(int i = 1; i <= getOrder(G); i++) {
      append(S, i);
   }
   
   // Run DFS on G and G-Transpose, processing the vertices in the second call
   // by decreasing finish times from the first call
   DFS(G, S);
   T = transpose(G);
   DFS(T, S);
   
   // Determine the strong components of G
   // Print the strong components of G to the output file in topologically sorted order.
   // Everytime a vertex has a NIL parent in the transpose of G, we have a SCC
   sccNum = 0;
   for(int i = 1; i <= getOrder(G); i++) {
      if(getParent(T, i) == NIL) sccNum++;
   }
   
   
   fprintf(out, "G contains %d strongly connected components:\n", sccNum);
   index = 1;
   moveTo(S, length(S) - 1 );
   while(getIndex(S) != -1 && index <= sccNum) {  
	  fprintf(out, "Component %d:", index);
	  while(getParent(T, getElement(S)) != NIL) {
		 prepend(R, getElement(S));
		 movePrev(S);
	  }
	  prepend(R, getElement(S));
	  printReverse(out, T, R);
	  movePrev(S);
	  index++;   
	  fprintf(out, "\n");
   }

   
   freeList(&S);
   freeList(&R);   
   freeGraph(&G);
   freeGraph(&T);   

   /* close files */
   fclose(in);
   fclose(out);

   return(0);
}
예제 #9
0
int main(int argc, char* argv[])
{
    int i;
    ListRef A = newList();
    ListRef B = newList();
	ListRef ACopy = NULL;
	ListRef AB_Cat = NULL;
	insertBack(A, 10);
	insertBack(A, 20);
	insertBack(A, 30);
	insertBack(A, 40);
	insertBack(A, 50);
	insertBack(A, 60);
	printf("equals(A,B)		: %d\n", equals(A, B));
	insertBack(B, 10);
	insertBack(B, 20);
	insertBack(B, 30);
	insertBack(B, 40);
	insertBack(B, 50);
	insertBack(B, 60);
	AB_Cat = catList(A, B);
	printf("printLIST(AB_Cat)	: ");
	printLIST(AB_Cat);
	ACopy = copyList(A);
	printf("printLIST(A)		: ");
	printLIST(A);
	printf("printLIST(ACopy)	: ");
	printLIST(ACopy);
	printf("equals(A,ACopy)		: %d\n", equals(A, ACopy));
	printf("equals(A,B)		: %d\n", equals(A, B));
	printf("printLIST(A)		: ");
	printLIST(A);
	moveTo(A, getLength(A));
	printf("offEnd(A)		: %d\n", offEnd(A));
	moveTo(A, 3);
	insertBeforeCurrent(A, 35);
	insertAfterCurrent(A, 45);
	printf("printLIST(A)		: ");
	printLIST(A);
	printf("getCurrent(A)		: %d\n", getCurrent(A));
	movePrev(A);
	printf("getCurrent(A)		: %d\n", getCurrent(A));
	deleteCurrent(A);
	printf("printLIST(A)		: ");
	printLIST(A);
	makeEmpty(B);
	deleteFront(A);
	printf("printLIST(A)		: ");
	printLIST(A);
	printf("getLength(A)		: %d\n", getLength(A));
	printf("isEmpty(A)		: %d\n", isEmpty(A));
	makeEmpty(A);
	printf("isEmpty(A)		: %d\n", isEmpty(A));
	printf("getLength(A)		: %d\n", getLength(A));
	/* printf("printLIST(A)		: ");
	printLIST(A); */
	insertFront(B, 50);
	insertBack(B, 60);
	insertFront(B, 40);
	insertBack(B, 70);
	insertFront(B, 30);
	insertBack(B, 80);
	insertFront(B, 20);
	insertBack(B, 90);
	insertFront(B, 10);
	printf("printLIST(B)		: ");
	printLIST(B);
	printf("offEnd(B)		: %d\n", offEnd(B));
	moveTo(B, 5);
	printf("offEnd(B)		: %d\n", offEnd(B));
	printf("getCurrent(B)		: %d\n", getCurrent(B));
	deleteCurrent(B);
	printf("printLIST(B)		: ");
	printLIST(B);
	/* printf("getCurrent(B) 	: %d\n", getCurrent(B));*/
	moveTo(B, 0);
	printf("getFront(B)		: %d\n", getFront(B));
	printf("getCurrent(B)		: %d\n", getCurrent(B));
	deleteFront(B);
	printf("printLIST(B)		: ");
	printLIST(B);
	printf("getFront(B)		: %d\n", getFront(B));
	/* printf("getCurrent(B)		: %d\n", getCurrent(B)); */
	moveTo(B, (getLength(B)-1));
	printf("getCurrent(B)		: %d\n", getCurrent(B));
	printf("getBack(B)		: %d\n", getBack(B));
	deleteBack(B);
	printf("getBack(B)		: %d\n", getBack(B));
	/* printf("getCurrent(B)		: %d\n", getCurrent(B)); */
	moveTo(B, (getLength(B)-1));
	printf("getCurrent(B)		: %d\n", getCurrent(B));
	printf("getBack(B)		: %d\n", getBack(B));
	deleteBack(B);
	printf("getBack(B)		: %d\n", getBack(B));
	printf("getCurrent(B)		: %d\n", getCurrent(B)); 
	
	
	
    return(0);
}
예제 #10
0
int main(int argc, char* argv[]){

// VARIABLE DECLARATION ///////////////////////////////////////////

    FILE *in, *out;
    char* token;
    char line[MAX_LEN];
    int x, y;
    Graph G, Gt;
    List stack = newList();

// ERROR CHECKING AND I/O PREP ////////////////////////////////////

    //verifies the correct number of arguments
     if(argc != 3){
        printf("Usage: %s <input file> <output file>\n", argv[0]);
        exit(1);
    }
    //opens the in file and out file
    in = fopen(argv[1], "r");
    out = fopen(argv[2], "w");
    //checks that they exist
    if(in == NULL)
    {
        printf("Unable to open file %s for reading\n", argv[1]);
        exit(1);
    }
    if(out == NULL)
    {
        printf("Unable to open file %s for writing\n", argv[2]);
        exit(1);
    }

// INPUT AND GRAPH CREATION ///////////////////////////////////////

     // get first line and store in x
    fgets(line, MAX_LEN, in);
    token = strtok(line, "\n");
    x = y = atoi(token);
    // create new graph of size x
    G = newGraph(x);

    // verify the 0 0 line hasn't been reached then get next line
    while(x != 0 && y != 0 && fgets(line, MAX_LEN, in) != NULL){
        // store first and second
        // numbers in x and y
        // respectively
        token = strtok(line, " ");
        x = atoi(token);
        token = strtok(NULL, " ");
        y = atoi(token);
        // add a new arc with
        // origin x and terminus y
        if( x != 0 && y != 0){
            addArc(G, x, y);
        }
    }
    // print out G's adjacency list representation
    fprintf(out, "Adjacency list representation of G:\n");
    printGraph(out, G);

// STRONGLY-CONNECTED-COMPONENTS ALGORITHM IMPLEMENTATION ///////////

    // Initialize the stack to contain the vertices
    // of G in ascending order
    for(int i = 1; i < getOrder(G); i++){
        append(stack, i);
    }
    // Run a depth first search on G using stack
    // as the processing order of the vertices,
    // after stack will hold the vertices sorted
    // in order of decreasing finish time
    DFS(G, stack);
    // Create a transpose graph of G
    Gt = transpose(G);
    // Run the depth first search again this time
    // on the transpose of G using the output
    // stack from the first call
    DFS(Gt, stack);
    // the resulting stack contains the strongly
    // connected components of G
    fprintf(out, "G contains %d strongly connected components:", getSCC(Gt));
    // for however many SCC's there are
    for(int i = 1; i <= getSCC(Gt); i++){
        // start at the bottom of the stack
        moveTo(stack, length(stack)-1);
        // move up until you reach a vertex with a
        // NIL parent, that is the root of a SCC
        while(Gt->parent[getElement(stack)] != NIL){
            movePrev(stack);
        }
        // print it as the first in its component list
        fprintf(out, "\nComponent %d: ", i);
        fprintf(out, "%d ", getElement(stack));
        moveNext(stack);
        // and move down the stack printing out vertices
        // until you reach the bottom
        while(getIndex(stack) >= 0){
            fprintf(out, "%d ", getElement(stack));
            moveNext(stack);
        }
        // now move back up the stack deleting as you
        // go until you reach the root of this SCC
        while(Gt->parent[back(stack)] != NIL){
            deleteBack(stack);
        }
        // and delete it
        deleteBack(stack);
    }

// CLEAN UP /////////////////////////////////////////////////////////

    fclose(out);
    fclose(in);

    freeList(&stack);
    stack = NULL;

    freeGraph(&G);
    freeGraph(&Gt);
    G = NULL;
    Gt = NULL;

    return (0);
}
예제 #11
0
int main(int argc, char* argv[]){
   
   
   FILE *out;

   out = fopen(argv[2], "w");



   List A = newList();
   List B = newList();
   List C = NULL;
   int i;

   for(i=1; i<=5; i++){
      append(A,i);
      prepend(B,i);
   }

   printList(out,A); 
   printf("\n");
   printList(stdout,B); 
   printf("\n");

   for(moveTo(A,0); getIndex(A)>=0; moveNext(A)){
      printf("%d ", getElement(A));
   }
   printf("\n");
   for(moveTo(B,length(B)-1); getIndex(B)>=0; movePrev(B)){
      printf("%d ", getElement(B));
   }
   printf("\n");

   C = copyList(A);
   printf("%s\n", equals(A,B)?"true":"false");
   printf("%s\n", equals(B,C)?"true":"false");
   printf("%s\n", equals(C,A)?"true":"false");

   printf("A's front = %d\n",    front(A));
   printf("A's back = %d\n",    back(A));
   deleteFront(A);
   deleteBack(A);
   printf("A's front = %d\n",    front(A));
   printf("A's back = %d\n",    back(A));

   moveTo(A,4);
   insertBefore(A,-1);
   moveTo(A,3);
   insertAfter(A,-2);
   moveTo(A,2);
   delete(A);
   printList(stdout,A);
   printf("\n");
   // printf("%d\n", length(A));

   clear(A);
   printf("%d\n", length(A));

   printf("entering A \n");
   freeList(&A);

   //clear(B);

   printf("A free, entering B \n");
   freeList(&B);

   //clear(C);

   printf("A/B free, entering C \n");
   freeList(&C);

   fclose(out);

   return(0);
}	 
예제 #12
0
int main(int argc, const char * argv[]) {
    
    char buffer[MAX_LEN];
    
    
    //checks for correct usage
    if( argc != 3 ){
        printf("Usage: Lex <input file> <output file>\n");
        exit(1);
    }
    
    // Check to see if input is open
    // opens the file
    FILE* input = fopen(argv[1], "r");
    FILE* output = fopen(argv[2], "w");
    
    // checks if files have been open and or created
    if(input == NULL){
        printf("Unable to open file %s\n", argv[1]);
        return 1;
    } else if (output == NULL){
        printf("Unable to open file %s\n", argv[2]);
        return 1;
    }
    
    char numOfVerticesChar[MAX_LEN];
    int numOfVertices;
    
    fgets (numOfVerticesChar, MAX_LEN, input);
    
    numOfVertices = atoi(numOfVerticesChar);
    
    
    Graph graph = newGraph(numOfVertices);
    
    
    while( fgets(buffer, MAX_LEN, input) != NULL) {
        
        int numOne = 0;
        int numTwo = 0;
        sscanf(buffer, "%d %d", &numOne, &numTwo);
        if(numOne == 0 && numTwo == 0)
            break;
        
        addArc(graph, numOne, numTwo);
    }
    
    fprintf(output, "Adjacency list representation of G:\n");
    
    printGraph(output, graph);
    
    fprintf(output,"\n");

    List S = newList();
    int i;
    for(i = 1; i <=numOfVertices; i++)
    {
        append(S, i);
    }
    
    
    DFS(graph, S);
    
    
    Graph graphTrans = transpose(graph);
    
    
    DFS(graphTrans, S);
    
    
    
    List connectedComp = newList();
    int counter = 0;
    for(moveTo(S,length(S)-1); getIndex(S) != -1; movePrev(S))
    {
        prepend(connectedComp, getElement(S));
        if(getParent(graphTrans,getElement(S)) == 0)
        {
            counter ++;
            clear(connectedComp);
        }
        
    }
    
    fprintf(output, "G contains %i strongly connected components: \n", counter);

    counter = 0;
    
    for(moveTo(S,length(S)-1); getIndex(S) != -1; movePrev(S))
    {
        prepend(connectedComp, getElement(S));
        if(getParent(graphTrans,getElement(S)) == 0)
        {
            counter ++;
            fprintf(output, "Component %i: ", counter);
            
            for(moveTo(connectedComp,0); getIndex(connectedComp) != -1; moveNext(connectedComp))
            {
                fprintf(output, "%d ",getElement(connectedComp));
                
            }
            clear(connectedComp);
            fprintf(output, "\n");
        }
    }
    
    
    fclose(input);
    fclose(output);
    
    
    freeGraph(&graphTrans);
    freeGraph(&graph);
    freeList(&S);
    freeList(&connectedComp);
    
    
    
    return 0;
}
예제 #13
0
파일: Lex.c 프로젝트: kpscanlon92/cmps101
int main (int argc, char * argv[]) {

   int n = 0;
   int lineNumber = 0;
   FILE *in, *out;
   char line[MAX_LEN];

   List L = newList();

   // check command line for correct number of arguments
   if( argc != 3 ){
     printf("Usage: %s <input file> <output file>\n", argv[0]);
     exit(1);
   }

   // open files for reading and writing 
   in = fopen(argv[1], "r");
   if( in==NULL ){
     printf("Unable to open file %s for reading\n", argv[1]);
     exit(1);
   }
   while( fgets(line, MAX_LEN, in) != NULL ) {
      n++;
   }
   fclose(in);
   
   char* lines[n];

   in = fopen(argv[1], "r");
   while( fgets(line, MAX_LEN, in) != NULL) {
      lines[lineNumber] = strdup(line);
      if(lineNumber > 0) {
         moveTo(L, lineNumber-1);
         int i = lineNumber - 1;
         char* tmp;
         tmp = lines[lineNumber];
         while(i > 0 && strcmp(tmp, lines[getElement(L)])<0) {
            movePrev(L);
            i--;
         }
         if(strcmp(tmp, lines[getElement(L)])<0) 
            insertBefore(L, lineNumber);
         else
            insertAfter(L, lineNumber);
      } else {
         append(L, lineNumber);
      }
      lineNumber++;
   }
   fclose(in);

   out = fopen(argv[2], "w");
   if( out==NULL ){
     printf("Unable to open file %s for writing\n", argv[2]);
     exit(1);
   }

   moveTo(L, 0);
   for(int i = 0; i < n; i++) {
      fprintf(out, lines[getElement(L)]);
      moveNext(L);
   }
   
   for(int i = 0; i < n; i++) {
      free(lines[i]);
   }

   freeList(&L);
   fclose(out);

   return(0);

}
예제 #14
0
int main (){

  /***Exercise List constructor***/
  ListHndl List;
  List = NULL;
  List = newList ();

  if(List){
    printf("List Created\n");
  }else{
    printf("List Not Created\n");
  }
  
  printf("isEmpty %d\n",isEmpty(List)); /*should print 1*/
  
  /***Populate with test data***/
  int i;
  for(i=0; i<=4; i++){
    insertAtFront(List,i);
  }
  
  printList(stdout, List);
  
  printf("isEmpty %d\n",isEmpty(List)); /*should print 0*/

  int j;
  for(j=5; j<=9; j++){
    insertAtBack(List,j);
  } 
  printList(stdout, List);
  
  /***Exercise all access functions***/
  printf("offEnd %d\n",offEnd(List));/*should print 0*/
  
  printf("atFirst %d\n",atFirst(List));/*should print 0*/
  
  printf("atLast %d\n",atLast(List));/*should print 0*/
  
  printf("getFirst %d\n", getFirst(List));/*should print 4*/
  
  printf("getLast %d\n", getLast(List));/*should print 9*/
  
  printf("getCurrent %d\n", getCurrent(List));/*should print 0*/
  
  /***Exercise all removal manipulation functions***/
  deleteLast(List);
  printList(stdout, List);
  printf("getLast %d\n", getLast(List));/*should print 8*/
  
  deleteFirst(List);
  printList(stdout, List);
  printf("getFirst 	\n", getFirst(List));/*should print 3*/
  
  deleteCurrent(List);
  printList(stdout, List);
  
  moveLast(List);
  printList(stdout, List);
  movePrev(List);
  printList(stdout, List);
  moveNext(List);
  printList(stdout, List);

  /***Exercise various edge cases***/  
  makeEmpty(List);
  insertAtFront(List, 40);
  moveFirst(List);
  deleteCurrent(List);
  
  insertAtFront(List, 41);
  insertAtBack(List, 42);
  moveFirst(List);
  insertBeforeCurrent(List, 43);
  printList(stdout, List);
  
  /***Exercise List destructors***/
  
  deleteCurrent(List);
  printList(stdout, List);
  
  makeEmpty(List);
  printf("offEnd %d\n",offEnd(List));/*should print 1*/
  

  freeList(&List);
  return(0);
}