void search(node *r,int mode){ int num = countList(r); if(root == NULL) { printf("\t\tList hasn't create !!\n"); return; } if ( mode == 1){ // search model int i,c = 0; node *p = root; char s[100]; printf("\t\tSearch by model :");scanf("%[^\n]",s);mfflush(); for (i = 0; i < num; i++) { if(!strcmp(s,p->element.model)) c++; } if(c != 0){ p = root; c = 0; printf("\t\tSearch result : \n"); for (i = 0; i < num; i++) { if(!strcmp(s,p->element.model)) printf("%-3d %-40s | %-3d gb | %-3.1f '' |%-10d VND\n",c+1,p->element.model,p->element.size,p->element.screen,p->element.price); p = p ->next; } } else { printf("\t\tNot found !!\n"); } } else { int i,c = 0,z = 0,sum = 0; long d; printf("\t\tSearch product slow than price :");scanf("%ld",&d);mfflush(); node *p = root; for (i = 0; i < num; i++) { if(p->element.price < d && p->element.price != -1) { c++; } p = p ->next; } if(c != 0 ){ printf("\t\tSearch result : \n"); p = root; sum = c; i = 0; for(;;){ c = z*PAGE; int k = PAGE + z*PAGE; k = (k < sum)?k:sum; printf("\t\t Page %d\n",z+1); for (;c < k;) { if(p == NULL) break; if(p->element.price < d && p->element.price != -1) { printf("%-3d %-40s | %-3d gb | %-3.1f '' |%-10d VND\n",c+1,p->element.model,p->element.size,p->element.screen,p->element.price); c++; } p = p ->next; } if(PAGE > sum ) return ; if(z == 0) { if(navi(1,0)== 1) z++; else return ; } else if(z*PAGE + PAGE > sum) { if(navi(0,1)==1) { z--; int j; for(j = 0 ; j < PAGE ; j++) p = pevNode(root,p); for(j = 0 ; j < PAGE ; j++) p = pevNode(root,p); } else return; } else { if((c=navi(1,1)) ==1 ) { z--; int j; for(j = 0 ; j < PAGE ; j++) p = pevNode(root,p); for(j = 0 ; j < PAGE ; j++) p = pevNode(root,p); } else if(c ==2) z++; else return ; } } } else { printf("\t\tNot Found !! \n"); } } }
void main( int argc, char* argv[] ) { FILE* pInputFile = NULL; FILE* pOutputFile = NULL; FILE** pFiles = NULL; struct Node* freqTable = NULL; struct ListNode* lsTree = NULL; struct HuffCodeRec* codeTable = NULL; int ch; struct timeb timeStart; struct timeb timeEnd; long timeExec; char inputFile[FILENAME_LEN]; char outputFile[FILENAME_LEN]; char* files[] = { inputFile, outputFile }; int needPrintCode = 0; int maxNumberChar = 0; //open input and output files if ( ( pFiles = openFiles( argc, argv, files, &needPrintCode ) ) == NULL ) return; pInputFile = pFiles[0]; pOutputFile = pFiles[1]; //fixed begin time ftime( &timeStart ); //load frequency table from input file printf( "load frequency table..." ); freqTable = loadListFromFileBin( pInputFile, &maxNumberChar ); printf( "\ncreate tree..." ); //build Huffman code tree list2lsTree( freqTable, &lsTree ); while ( countLsTree( lsTree ) > 1 ) createTree( &lsTree ); //decode data of input file and write decoded characters to output file printf( "\ndecode..." ); while( ( ch = fgetc( pInputFile ) ) != EOF ) { charHuffDecode( (unsigned char)ch, lsTree, pOutputFile, maxNumberChar ); } //print Huffman code table if need if ( needPrintCode == 1 ) { printf( "\n---------------Code table----------------\n" ); createHuffCodeTable( &codeTable, lsTree ); printHuffCodeTable( codeTable ); printf( "\n-----------------------------------------\n" ); } //fixed end time ftime( &timeEnd ); //computing execute time timeExec = ( timeEnd.time - timeStart.time ) * 1000 + timeEnd.millitm - timeStart.millitm; //print results printf( "\nSize of input file %s is %d bytes", files[0], fileSize( pInputFile ) ); printf( "\nSize of output file %s is %d bytes", files[1], fileSize( pOutputFile ) ); printf( "\nUnique characters: %d", countList( freqTable ) ); printf( "\nTime of execution: %d milliseconds", timeExec ); //clear memory and close files deleteList( freqTable ); deleteLsTree( lsTree ); deleteHuffCodeTable( codeTable ); fclose( pInputFile ); fclose( pOutputFile ); printf( "\nDone" ); }
static unsigned int tagtransform_c_filter_rel_member_tags( struct keyval *rel_tags, int member_count, struct keyval *member_tags, const char **member_role, int * member_superseeded, int * make_boundary, int * make_polygon, int * roads) { char *type; struct keyval tags, *p, poly_tags; int i; /* Get the type, if there's no type we don't care */ type = getItem(rel_tags, "type"); if (!type) return 1; initList(&tags); initList(&poly_tags); /* Clone tags from relation */ p = rel_tags->next; while (p != rel_tags) { /* For routes, we convert name to route_name */ if ((strcmp(type, "route") == 0) && (strcmp(p->key, "name") == 0)) addItem(&tags, "route_name", p->value, 1); else if (strcmp(p->key, "type")) /* drop type= */ addItem(&tags, p->key, p->value, 1); p = p->next; } if (strcmp(type, "route") == 0) { const char *state = getItem(rel_tags, "state"); const char *netw = getItem(rel_tags, "network"); int networknr = -1; if (state == NULL ) { state = ""; } if (netw != NULL ) { if (strcmp(netw, "lcn") == 0) { networknr = 10; if (strcmp(state, "alternate") == 0) { addItem(&tags, "lcn", "alternate", 1); } else if (strcmp(state, "connection") == 0) { addItem(&tags, "lcn", "connection", 1); } else { addItem(&tags, "lcn", "yes", 1); } } else if (strcmp(netw, "rcn") == 0) { networknr = 11; if (strcmp(state, "alternate") == 0) { addItem(&tags, "rcn", "alternate", 1); } else if (strcmp(state, "connection") == 0) { addItem(&tags, "rcn", "connection", 1); } else { addItem(&tags, "rcn", "yes", 1); } } else if (strcmp(netw, "ncn") == 0) { networknr = 12; if (strcmp(state, "alternate") == 0) { addItem(&tags, "ncn", "alternate", 1); } else if (strcmp(state, "connection") == 0) { addItem(&tags, "ncn", "connection", 1); } else { addItem(&tags, "ncn", "yes", 1); } } else if (strcmp(netw, "lwn") == 0) { networknr = 20; if (strcmp(state, "alternate") == 0) { addItem(&tags, "lwn", "alternate", 1); } else if (strcmp(state, "connection") == 0) { addItem(&tags, "lwn", "connection", 1); } else { addItem(&tags, "lwn", "yes", 1); } } else if (strcmp(netw, "rwn") == 0) { networknr = 21; if (strcmp(state, "alternate") == 0) { addItem(&tags, "rwn", "alternate", 1); } else if (strcmp(state, "connection") == 0) { addItem(&tags, "rwn", "connection", 1); } else { addItem(&tags, "rwn", "yes", 1); } } else if (strcmp(netw, "nwn") == 0) { networknr = 22; if (strcmp(state, "alternate") == 0) { addItem(&tags, "nwn", "alternate", 1); } else if (strcmp(state, "connection") == 0) { addItem(&tags, "nwn", "connection", 1); } else { addItem(&tags, "nwn", "yes", 1); } } } if (getItem(rel_tags, "preferred_color") != NULL ) { const char *a = getItem(rel_tags, "preferred_color"); if (strcmp(a, "0") == 0 || strcmp(a, "1") == 0 || strcmp(a, "2") == 0 || strcmp(a, "3") == 0 || strcmp(a, "4") == 0) { addItem(&tags, "route_pref_color", a, 1); } else { addItem(&tags, "route_pref_color", "0", 1); } } else { addItem(&tags, "route_pref_color", "0", 1); } if (getItem(rel_tags, "ref") != NULL ) { if (networknr == 10) { addItem(&tags, "lcn_ref", getItem(rel_tags, "ref"), 1); } else if (networknr == 11) { addItem(&tags, "rcn_ref", getItem(rel_tags, "ref"), 1); } else if (networknr == 12) { addItem(&tags, "ncn_ref", getItem(rel_tags, "ref"), 1); } else if (networknr == 20) { addItem(&tags, "lwn_ref", getItem(rel_tags, "ref"), 1); } else if (networknr == 21) { addItem(&tags, "rwn_ref", getItem(rel_tags, "ref"), 1); } else if (networknr == 22) { addItem(&tags, "nwn_ref", getItem(rel_tags, "ref"), 1); } } } else if (strcmp(type, "boundary") == 0) { /* Boundaries will get converted into multiple geometries: - Linear features will end up in the line and roads tables (useful for admin boundaries) - Polygon features also go into the polygon table (useful for national_forests) The edges of the polygon also get treated as linear fetaures allowing these to be rendered seperately. */ *make_boundary = 1; } else if (strcmp(type, "multipolygon") == 0 && getItem(&tags, "boundary")) { /* Treat type=multipolygon exactly like type=boundary if it has a boundary tag. */ *make_boundary = 1; } else if (strcmp(type, "multipolygon") == 0) { *make_polygon = 1; /* Copy the tags from the outer way(s) if the relation is untagged */ /* or if there is just a name tag, people seem to like naming relations */ if (!listHasData(&tags) || ((countList(&tags) == 1) && getItem(&tags, "name"))) { for (i = 0; i < member_count; i++) { if (member_role[i] && !strcmp(member_role[i], "inner")) continue; p = member_tags[i].next; while (p != &(member_tags[i])) { addItem(&tags, p->key, p->value, 1); p = p->next; } } } /* Collect a list of polygon-like tags, these are used later to identify if an inner rings looks like it should be rendered separately */ p = tags.next; while (p != &tags) { if (!strcmp(p->key, "area")) { addItem(&poly_tags, p->key, p->value, 1); } else { for (i = 0; i < exportListCount[OSMTYPE_WAY]; i++) { if (strcmp(exportList[OSMTYPE_WAY][i].name, p->key) == 0) { if (exportList[OSMTYPE_WAY][i].flags & FLAG_POLYGON) { addItem(&poly_tags, p->key, p->value, 1); } break; } } } p = p->next; } } else { /* Unknown type, just exit */ resetList(&tags); resetList(&poly_tags); return 1; } /* If we are creating a multipolygon then we mark each member so that we can skip them during iterate_ways but only if the polygon-tags look the same as the outer ring */ if (make_polygon) { for (i = 0; i < member_count; i++) { int match = 0; struct keyval *p = poly_tags.next; while (p != &poly_tags) { const char *v = getItem(&(member_tags[i]), p->key); if (!v || strcmp(v, p->value)) { match = 0; break; } match = 1; p = p->next; } if (match) { member_superseeded[i] = 1; } else { member_superseeded[i] = 0; } } } resetList(rel_tags); cloneList(rel_tags, &tags); resetList(&tags); add_z_order(rel_tags, roads); return 0; }
int main (void) { /* program to coordinate the menu options and calls the requested function */ struct node * first = NULL; /* pointer to the first list item */ char option[strMax]; /* user response to menu selection */ printf ("Program to Maintain a List of Names\n"); while (1) { /* print menu options */ printf ("Options available\n"); printf ("I - Insert a name into the list\n"); printf ("D - Delete a name from the list\n"); printf ("C - Count the number of items on the list\n"); printf ("F - Move an item to the front of the list\n"); printf ("L - Print the last item on the list (iteratively)\n"); printf ("M - Print the last item on the list (recursively)\n"); printf ("P - Print the names on the list (iteratively)\n"); printf ("S - Print the names on the list (recursively)\n"); printf ("R - Print the names in reverse order\n"); printf ("Q - Quit\n"); /* determine user selection */ printf ("Enter desired option: "); scanf ("%s", option); switch (option[0]) { case 'I': case 'i': addName(&first); break; case 'D': case 'd': deleteName(&first); break; case 'C': case 'c': countList(first); break; case 'F': case 'f': putFirst(&first); break; case 'L': case 'l': printLast(first); break; case 'M': case 'm': printLastRec(first); break; case 'P': case 'p': print(first); break; case 'S': case 's': printRec(first); break; case 'R': case 'r': printReverse(first); break; case 'Q': case 'q': printf ("Program terminated\n"); return 0; break; default: printf ("Invalid Option - Try Again!\n"); continue; } } }
int main (void) { /* program to coordinate the menu options and calls the requested function */ struct node * first = NULL; /* pointer to the first list item */ char option[strMax]; /* user response to menu selection */ printf ("Program to Maintain a List of Robot Actions\n"); while (1) { /* print menu options */ printf ("Options available\n"); printf ("I - Insert an action into the list\n"); printf ("D - Delete an action from the list\n"); printf ("C - Count the number of items in the list\n"); printf ("F - Move an item to the front of the list\n"); printf ("L - Print the last item in the list\n"); printf ("P - Print the actions in the list and the UIDs of the nodes\n"); printf ("R - Print the actions and UIDs in reverse order\n"); printf ("E - Execute all the action commands contained in the list\n"); printf ("Q - Quit\n"); /* determine user selection */ printf ("Enter desired option: "); scanf ("%s", option); switch (option[0]) { case 'I': case 'i': addAction(&first); break; case 'D': case 'd': deleteAction(&first); break; case 'C': case 'c': countList(first); break; case 'F': case 'f': putFirst(&first); break; case 'L': case 'l': printLast(first); break; case 'P': case 'p': print(first); break; case 'R': case 'r': printReverse(first); break; case 'E': case 'e': executeActions(first); break; case 'Q': case 'q': printf ("Program terminated\n"); return 0; break; default: printf ("Invalid Option - Try Again!\n"); continue; } } }