void criticalRoute(Graph* g, char* captital){
  t = g;
  while(t){
      Edge *v1 = NULL, *v2 = NULL;
      v1 = t->edges;
      while(v1){
          v2 = v1->next;
          char *city_name = (char*) malloc(sizeof(char)*200);
          strcpy(city_name, v1->to);
          disconnectGraph(g, t->id, v1->to);
          ArrayList *l = reachble_cities(g, t);

          if(!findList(l, capital)){
              printf("[%s %s] \n", t->id, city_name);
          }
          connectGraph(g, t->id, city_name);
          v1 = v2;
          destroyList(l);
          free(city_name);
          if(!v1){
              break;
          }
          v2 = v1->next;
      }
      t = t->next;
    }
}
Esempio n. 2
0
/**
 * Stores a word in the hash-list.
 *
 * @param hl      A HashList structure
 * @param str     The string to be saved
 * @param str_len Length of the string
 * @returns Whether the word has been stored, or simply incremented the word counter
 */
int hl_add_word(HashList *hl, char *str, int str_len)
{
  int h, r;
  char *copybuffer;
  List *l;
  ListData *ld;
  
  h = hash(str, str_len, hl->size);

  // printf("[%16s] Calculated hash for [%s]: [%d]\n", "hl_add_word", str, h);
  
  l = &(hl->buckets[h]);
  
  ld = findList(l, str);
  if ( ld != NULL )
  {
    ld->numTimes++;
    r = 1;
  }
  else
  {
    copybuffer = malloc((strlen(str) + 1 ) * sizeof(char));
    strcpy(copybuffer, str);
    
    ld = malloc(sizeof(ListData));
    ld->primary_key = copybuffer;
    ld->numTimes = 1;
    
    insertList(l, ld);

    r = 0;
  }

  return r;
}
Esempio n. 3
0
void main()
{
    int a[10] = {2, 4, 6, 8, 10, 12, 14, 16, 18, 20};
    int i;
    struct List L;
    initList(&L, 5);
    for(i = 0; i < 10; i++){
        insertLastList(&L, a[i]);
    }
    insertPosList(&L, 11, 48);        insertPosList(&L, 1, 64);
    printf("%d ", getElem(&L, 1));
    traverseList(&L);
    printf("%d ", findList(&L, 10));
    updatePosList(&L, 3, 20);
    printf("%d ", getElem(&L, 3));
    traverseList(&L);
    deleteFirstList(&L);            deleteFirstList(&L);
    deleteLastList(&L);                deleteLastList(&L);
    deletePosList(&L, 5);            ;deletePosList(&L, 7);
    printf("%d ", sizeList(&L));
    printf("%d ", emptyList(&L));
    traverseList(&L);
    clearList(&L);
    return 0;
}
Esempio n. 4
0
 /* Find a node that contains the integer 'val' inside */
void findList(typeList lis, int val, typeList *res) {
    if (emptyList(lis))
        *res = NULL;
    else if (lis->data == val)
        *res = lis;
    else
        findList(lis->next, val, res);
}
Esempio n. 5
0
/*
 * Routine: 
 * Purpose: 
 * Algorithm:
 * Data Structures:
 *
 * Params:
 * Returns:
 * Called By: 
 * Calls: 
 * Assumptions:
 * Side Effects:
 * TODO: None
 */
substitution_t *
findSubstitution(template_t *t, char *name, int *nUse)
{
	int nChars,
		nUseCount;
	substitution_t *pSub;
	static substitution_t tempSubstitution;
	static int bInit = 0;

	if (!bInit)
	{
		memset(&tempSubstitution, 0, sizeof(struct SUBSTITUTION_T));
		tempSubstitution.name = malloc(100 * sizeof(char));
		MALLOC_CHECK(tempSubstitution.name);
		bInit = 1;
	}
	
	/* exclude any numeric suffix from search, but update nUses */
	nChars = strcspn(name, "0123456789");
	if (strlen(name) > 100)
		tempSubstitution.name = realloc(tempSubstitution.name, strlen(name) + 1);
	strncpy(tempSubstitution.name, name, nChars);
	tempSubstitution.name[nChars] = '\0';
	pSub = findList(t->SubstitutionList, (void *)&tempSubstitution);
	if (!pSub) /* the substitution could be global; add a local reference */
	{
		pSub = findList(g_Template->SubstitutionList, (void *)&tempSubstitution);
		if (pSub)
			addList(t->SubstitutionList, pSub);
	}
	if (pSub)
	{
		nUseCount = atoi(name + nChars);
		if (nUseCount == 0)
			nUseCount = 1;
		if (nUseCount > pSub->nUse)
			pSub->nUse = nUseCount;
		if (nUse)	/* we're interested in the usage number */
			*nUse = nUseCount;
		return(pSub);
	}
	
	return(NULL);
}
Esempio n. 6
0
void VParser::newList(const char *listName)
{
    LList   *curList;
    
    curList = findList(listName);
    if (curList == NULL) {
        curList = new(LList);
        curList->Name  = new(char[strlen(listName)  + 1]);
        strcpy(curList->Name, listName);        
        lists.append(curList);
    }
    currentList = curList;
    currentListRow = currentList->rows.first();
}
Esempio n. 7
0
void insertWord_HashTable(List * tablaHash, char * subcadena){

	int valor_hash, n_lletres;

	ListData *listData;

	n_lletres = (int)strlen(subcadena);

	if ( n_lletres > max_word )
		max_word = n_lletres;

	valor_hash = funcHash(subcadena);

	/* Search if the key is in the tree */
	listData = findList(&tablaHash[valor_hash], subcadena);

	if(listData != NULL){
		
		/* We increase it the number of times that shows up */
		listData->numTimes++;

	}else{

		/*	
			If the key is not in the list, allocate memory for the data and
			insert it in the list
       	 */
		listData = malloc(sizeof(ListData));
		listData->key = malloc(sizeof(TYPEKEY) * MAXWORD);
		
		strcpy(listData->key, subcadena);

		listData->numTimes = 1;
	
		insertList(&tablaHash[valor_hash], listData);

	}
}
Esempio n. 8
0
void VParser::doParsing(void)
{
    QString curItem;
    QString curListItem;
    QString tmpSt;
    QString workStr;
    QString listName;
    QString listBlock;
    QString endTag;
    QString token;
    QString strtoken;
    int     rpos;
    int     toklen;
    char    tmpStr[1024];
    
    for (uint i = 0; i < fcontents.count(); i++) {
        curItem = fcontents.at(i);
        if (curItem.find("{") >= 0) {
            // We have something to parse.
            // See if it is a list.  If it is not, then just do a replace on
            // it, if it is, a list, do different things.
            if (curItem.find("{List ") >= 0) {
                // Okay, we need to get everything between the open and
                // close list tags into a single block for parsing.
                // For right now, we'll require that the {List ...} and
                // {EndList ...} tags be on lines of their own.
                // We will then pass the block and the list to the
                // parser.
                
                // Set up our work string.
                workStr = curItem;
                
                // Get the token from the string.
                rpos = workStr.find("}");
                toklen = rpos - workStr.find("{") + 1;
                token  = workStr.mid(workStr.find("{"), toklen);
                strtoken = token.mid(1, toklen-2);
                
                // Now, get the list name from the strtoken
                listName = strtoken;
                listName.replace(QRegExp("List "), "");
                
                // Now set up our ending string so we can search for the
                // end tag.
                endTag = "{EndList ";
                endTag.append(listName);
                endTag.append("}");
                
                // Now, continue looping through our list and append
                // things to the block we'll be sending through the
                // parser.
                listBlock = "";
                for (uint j = 0; j < fcontents.count(); j++) {
                    curListItem = fcontents.at(j);
                    if (curListItem.find(endTag) >= 0) {
                        // We've found our ending tag.  Abort the scan
                        break;
                        // curListItem = 0;
                    } else {
                        // We didn't find our tag, so append it to the string
                        // to the block to parse.
                        listBlock.append(curListItem);
                    }
                }
                
                // Reset our counter for the main loop
                fcontents.find(curListItem);
                // curItem = curListItem;
                
                // Since we're out of the loop, we have the list block to
                // parse.  First, strip out the list references to all of
                // the {ListName:...} so they just read as {...}
                workStr = "{";
                workStr.append(listName);
                workStr.append(":");
                listBlock.replace(QRegExp(workStr), "{");
                
                // Now, find the list.
                strcpy(tmpStr, listName);
                LList   *tmpList = findList(tmpStr);
                if (tmpList != NULL) {
                    // Got it.  Parse the block for each list element.
                    EList       *curRow;
                    for (int n = 0; n < tmpList->rows.count(); n++) {
                        curRow = tmpList->rows.at(n);
                        parseBlock(listBlock, &curRow->columns);
                    }
                } else {
                    fprintf(stderr, "List '%s' not found!\n", (const char *) listName);
                }
                
                
            } else {
                // Okay, no list items.  We can just parse the
                // string as-is.
                parseBlock(curItem, &elements);
            }
            
        } else {
            pcontents.append(curItem);
        }
    }
}