Ejemplo n.º 1
0
void testList()
{
  list mylist;
  mylist.head = 0x0;
  mylist.count = 0;
  mylist.current = 0x0;
  int i= 0;
  
  addToSortedList(&mylist, 1804289383);
  addToSortedList(&mylist, 846930886);
  searchList( &mylist, 846930886);
  list temp;
  copyList( &temp, &mylist);
  searchList(&temp, 846930886);
  for( i = 0; i <= 2000; i ++)
    {
      int x = rand();
      addToSortedList(&mylist, x);
      list temp;
      copyList(&temp,& mylist);
      if(!searchList( &mylist, x) || !searchList(&temp, x))
	{
	  printf ("\nERROR %d \n", x);
	  i = 2001;
	}
      else 
	{
	  printf("%d\t", x);
	}
      deleteList(& temp, blanko);
    }
}
Ejemplo n.º 2
0
// binary search list for given IP & return filter group, or -1 on failure
int ipinstance::searchList(int a, int s, const uint32_t &ip) {
	if (a > s) return -1;
	int m = (a + s) / 2;
	if (iplist[m] == ip) return iplist[m].group;
	if (iplist[m] < ip) return searchList(m + 1, s, ip);
	if (a == s) return -1;
	return searchList(a, m - 1, ip);
}
/**
 * FUNCTION NAME: processJoinReq
 *
 * DESCRIPTION: This function is run by the coordinator to process JOIN requests
 */
void MP1Node::processJoinReq(void *env, char *data, int size) {
    Member *node = (Member*)env;

    //first get the new node's info by deserializing
    Address newaddr;
    long heartbeat;
    memcpy(newaddr.addr, data, sizeof(newaddr.addr));
    memcpy(&heartbeat, data+sizeof(newaddr.addr), sizeof(long));

    int id = *(int*)(&newaddr.addr);
    short port = *(short*)(&newaddr.addr[4]);

    //second serialize the table(put it in a string form)
    char *table = serialize(node);

    //next construct a message: type: JOINREPLY, content: table
    size_t sz = sizeof(MessageHdr) + 1 + strlen(table);
    MessageHdr *msg = (MessageHdr *) malloc(sz * sizeof(char));
    msg->msgType = JOINREP;
    char * ptr = (char *) (msg+1);
    memcpy(ptr, table, strlen(table)+1);

    emulNet->ENsend(&node->addr, &newaddr, (char *)msg, (int)sz);
    free(msg);
    free(table);

    vector<MemberListEntry>::iterator it;
    it = searchList(id, port);
    // If the iterator returned points to the end of the list, then it is not found
    if ( it == memberNode->memberList.end() ) {
    	addEntryToMemberList(id, port, heartbeat);
    }
    
    return;
}
/**
 * FUNCTION NAME: deserializeAndUpdateTable
 *
 * DESCRIPTION: Deserialize the message and update the membership list
 */
char* MP1Node::deserializeAndUpdateTable(const char *msg){
    char *buffer = NULL;
    asprintf(&buffer, "%s", msg);

    char * pch;
    pch = strtok (buffer,"|");
    while (pch != NULL) {
        char *row = NULL;
        asprintf(&row, "%s", pch);
        int id;
        short port;
        long heartbeat;
        long timestamp;

        sscanf(row,"%d:%hi~%ld~%ld", &id, &port, &heartbeat, &timestamp);
        vector<MemberListEntry>::iterator found = searchList(id, port);
    
        // If the entry already exists and the new heartbeat is bigger, do an update
        if( found != memberNode->memberList.end() ) {
            if( (*(found)).getheartbeat() < heartbeat ) {
            	(*(found)).setheartbeat(heartbeat);
            	(*(found)).settimestamp(par->getcurrtime());
            }
        }   
        else {
            addEntryToMemberList(id, port, heartbeat);
        }     
        pch = strtok (NULL, "|");

    }
    return NULL;
}
Ejemplo n.º 5
0
int tag_word( char *mem ){
	char in=0,out=1,eword=-1,key_run=0;
	char *pt=buf_word;
	first_hash->key=0;
	while ( *mem!=NULL ){
		if( (*mem>='a'&&*mem<='z')||(*mem>='A'&&*mem<='Z')||*mem==0x5f )
		{
			in=1;
			if(in==1&&out==1) {
				eword=1;
				cpyStringn( buf_word,mem,idsize(mem));
				if( !searchList(buf_word,keyword) ) {
					hashPt->self=hashPt;	// init it's self of each element of id_table
					if( !ifExistInHash( buf_word,id_table,first_hash->key ) ){ 
						cpyString(hashPt->self->word,buf_word);
						++first_hash->key;
						hashPt++;
					}
				}
			}
			out=0;
		}
		if( !((*mem>='a'&&*mem<='z')||(*mem>='A'&&*mem<='Z')||(*mem>='0'&&*mem<='9')||*mem==0x5f) ){
			in=0;
			if( in==0&&out==0) eword=0;
			out=1;
		}
		mem++;
	}
	hashPt=id_table;
	return 0;
}
Ejemplo n.º 6
0
//busca e imprime resultados e relacionados
void GoogleSearch(SiteList* slist){
	int i, j, nkeywords = 1;
	SiteList* resultList = NULL;
	SiteList *copy = copyList(slist);
	resultList = buildSList();

	// obtem a lista de palavras
	char **keywords = getKeywordsList(slist, &nkeywords);

	// busca a primeira palavra - palavra digitada
	searchList(copy, resultList, keywords[0]);

	//verificando se a lista de resultados está vazia
	if(resultList->header->next != resultList->header){
		printf("Resultados encontrados: %d\n",resultList->tam);
		printSiteList(resultList,'d');
	} else {
		printf("Resultados encontrados: 0\n");
	}
	printf("\n");
	// apagando valores ja imprimidos
	clearAuxList(resultList);
	// gerando nova lista
	resultList = buildSList();

	//buscando por palavras relacionadas
	for(i = 1; i < nkeywords; i++){
		searchList(copy, resultList, keywords[i]);
	}

	//imprimindo sites relacionados
	if(resultList->header->next != resultList->header){
		printf("Resultados relacionados: %d\n",resultList->tam);
		printSiteList(resultList,'d');
	}

	//liverando a copia e a lista de palavras relacionadas
	clearAuxList(copy);
	clearAuxList(resultList);

	// liberando lista de palavras
	for(i = 0; i < nkeywords; i++){
		free(keywords[i]);
	}
	free(keywords);

}
Ejemplo n.º 7
0
node * searchEntry(node ** book, char * name){
  
  
  
  
      return searchList(book[((int)name[0])-65], name);
  
  
}
Ejemplo n.º 8
0
int main(int argc, char *argv[])
{
	// Make sure there is a filename argument to avoid error
	if (argc <= 1)
	{
		printf("No filename argument found, please ry again.\n");
		exit(0);
	}

	char *fileName = argv[1];
	int *list, count = 5, i = 0;
	list = (int*)malloc(count*sizeof(int));

	// Read numbers from file to list
	FILE* f = fopen (fileName , "r");
	while (!feof (f))
	{
		if (i >= count - 1)
		{
			count *= 2;
			list = realloc(list, count*sizeof(int));
		}
		fscanf (f, "%d", &list[i]);
		i ++;
	}
	fclose (f);
	count = i;
	list = realloc(list, count*sizeof(int));
	
	// Take input and choose sorting algorithm
	int selection = -1;
	while (selection < 0 || selection > 3)
	{
		printf("Select sorting algorithm (1-3):\n");
		printf("[1] Bubble sort\n");
		printf("[2] Shell sort\n");
		printf("[3] Insertion sort\n");

		scanf("%d", &selection);
	}
	switch(selection)
	{
		case 1:
			bubbleSort(list, count);
			break;
		case 2: 
			shellSort(list, count);
			break;
		case 3: 
			insertSort(list, count);
			break;
	}

	searchList(list, count);

	free(list);
}
Ejemplo n.º 9
0
/* == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == */
int main(int argc, char *argv[])
{
	CDLL list;
	int i,direction, k;
	CDLL_NODE *currNode;

	if (argc < 4)
	{
		printf("You must supply 3 values on the cmd line after %s:\n", argv[0]);
		printf("1: name of an input file contaning n names/labels of the members of the circle\n");
		printf("2: an integer:  k < n  ,  indicating that after deleting the selected starting element, k members are skipped before another deletions until all the members are deleted\n");
		printf("3: a string \"CW\" or \"CCW\" for clockwise counter-clockwise. This is the direction\n");
		printf("   you will move as you advance around the ring deleting members\n");
		exit( EXIT_FAILURE );
	}

	k  = atoi(argv[2]); /* assume valid int < n */
	if (strcmp(argv[3],"CW")==0)
		direction = CLOCKWISE; /* follow the NEXT ptr */
	else
		direction = COUNTERCLOCKWISE; /* follow the PREV ptr */

	/* Initialize CDLL (set head ptr NULL and set the cmp function */
	initList(&list, compareString,printString,freeString);
	loadList(&list,argv[1]);
	printf("\nLIST: ");printList(list, CLOCKWISE, BRIEF ); /* we follow the NEXT ptr around the ring, not the PREV ptr */

	do /* prompt user for a member to start the counting with */
	{
		char *name;
		printf("\nchoose a name as the starting point in the circle: ");
		if (!mygetline( &name,stdin)) fatal("mygetline failed in main reading from stdin.");
		currNode = searchList( list, name); // if user enters non-existent name it will ret NULL
		free( name );
	} while (!currNode);

	while (list.head) /* while list has any members left */
	{
		printf("\nDELETING: "); printString( currNode->data, BRIEF); fflush(stdout);
		currNode = deleteNode( &list, currNode, direction );
		if (!currNode)
		{
			printf("  <-- was the last man standing!\n");
			break;
		}
		printf("\nLIST: "); fflush(stdout);
		printList(list, CLOCKWISE, BRIEF );
		printf("RESUMING AT: "); printString( currNode->data, BRIEF ); printf( " and skipping %d elements \n", k );
		for ( i=1 ; i<=k ; ++i )
			if (direction==CLOCKWISE)
				currNode = currNode->next;
			else
				currNode=currNode->prev;

	} /* END WHILE - END OF GAME */
    return EXIT_SUCCESS;
}
Ejemplo n.º 10
0
Node<T>* List<T>::searchList(int key, Node<T>* curr){
    if(curr == NULL){
        return NULL;
    }
    
    if(curr->key == key){
        return curr;
    }
    
    return searchList(key, curr->next);
}
Ejemplo n.º 11
0
Archivo: D.c Proyecto: jpbat/aed2011
int searchList(nodePtr sl, char* word, int k)
{
    if(sl == NULL)
		return 0;
    
    else if( strcmp(word, sl->info.word) == 0)
    {
		sl->info.counter++;
		return 1;
	}
    
    else if(less(sl, word, k))
    {
		if(k == 0)
		{
			return 0;
        } 
		return searchList(sl, word, k-1);
    }
	t++;
    return searchList(sl->next[k], word, k);
}
Ejemplo n.º 12
0
int main (void)
{
/*	Local Definitions */
	NODE  *pList;
	NODE  *pPre;
	NODE  *pCur;
	DATA   data;
	double avrg;
	int    success;

/*	Statements */
	printf("Begin key-sequenced list functions\n\n");
	pList = NULL;
	
	/*	Build List */
	pList = buildSeq("P14CHRON.DAT");
	if (!pList)
	   {
	    printf("Error building key-sequenced file\a\n");
	    exit  (100);
	   } /* if */
	   
	printf("List Built\nContents: ");
	printList (pList);
	
	printf("\nInsert data tests.\n");
	printf("Enter first integer          : ");
	scanf ("%d", &data.key);
	do
	   {
	    /* Determine insert position */
	    success = searchList (pList, &pPre, &pCur, data.key);
	    if (!success)
	        pList = insertNode(pList, pPre, data);
	    else
	        printf("Duplicate data.\a\n");
	        
	    printf("Enter an integer <-1> to stop: ");
	    scanf ("%d", &data.key);
	   } while (data.key != -1);
        
	printf("\nData Inserted\nContents: ");
	printList (pList);
	
	avrg = averageList(pList);
	printf("\nData average: %.1f\n", avrg);
	

	printf("\nKey-sequenced tests complete.\n");
	return 0;
} /* main */
int main(int argc, char *argv[]) {

SensorInfo *head = addSensor("Solar Panel", "V");
SensorInfo *node1 = addSensor("Test", "N/A");
SensorInfo *node2 = addSensor("Time",":");
SensorInfo *node3 = addSensor("Date", "\\");
addNodeToList(head, node1);
addNodeToList(head, node2);
addNodeToList(head, node3);
printlist(head);
printf("Size of SensorInfo: %lu bytes.\n\n", sizeof(*head));
SensorInfo *find = searchList("Date", head);
printf("Node Found: %s\n", find->_sensorName);
return 0;	
}
Ejemplo n.º 14
0
/*
 *      bListContains
 *
 *	Author:	Christian Schafmeister (1991)
 *
 *      Find out if a list contains a particular object.
 *      
 *      Return:
 *              FALSE if the element is not in the list.
 */
BOOL
bListContains( LIST lList, GENP PPtr )
{
NODEP   *nPPPrev;
NODEP	nPPrevious;

                /* If the list is empty then return */

    if ( lList->nPFirstNode==NULL ) return(FALSE);

                /* Search the list for the object */
    nPPPrev = searchList( &(lList->nPFirstNode), (OBJEKT)PPtr, &nPPrevious );
    if ( nPPPrev == NULL ) return(FALSE);
    return(TRUE);
}
Ejemplo n.º 15
0
/* Returns the ith search path from the list as computed by searchList() */
static const char * getSearchPath(int i)
{
    static const char * list = 0;
    static const char * path[MAX_SEARCH_PATHS] = {0};
    static int end = 0;
    if (!list && !end) 
        list = searchList();
    while (!path[i] && !end) 
    {
        path[i] = strsep((char**)&list, ":");
        if (path[i][0] == 0)
            path[i] = 0;
        end = list == 0;
    }
    return path[i];
}
Ejemplo n.º 16
0
Object_Pointer tag_Func_Name( char* mem ) {
	unsigned p=0,nest1=0,nest2=0;
	char in=0,out=1,cin=0,cout=1,fix=0,inword=0;
	FuncObj[0].val=0;
	char temp[256];
	while( *(mem+p)!=NULL ){	
		if( (mem[p]>='a'&&mem[p]<='z')||(mem[p]>='A'&&mem[p]<='Z')||mem[p]==0x5f ){
			in=1;
			if( in==1&&out==1 ) {
				inword=1;
				if( fix==0 ) {
					cpyStringn( temp,mem+p,idsize(mem+p) );
				}
			}
			out=0;
		}
		if( !((mem[p]>='a'&&mem[p]<='z')||(mem[p] >='A'&&mem[p]<='Z')||(mem[p]>='0'&&mem[p]<='9')||mem[p]==0x5f) ) {
			in=0;
			if( in==0&&out==0 ) inword=0;
			out=1;
		}
		if( mem[p]==0x28 ) {
			fix=1;
			if( ppos1->level==0 ){
				ppos1->begin=p; ppos1->beginp=mem+p; 
				ppos1->level=1; 
			}
			if( ppos1->level==1 ) nest1++;
		}
		if( mem[p]==0x29 ) {
			if( ppos1->level==1&&nest1!=0 ) nest1--;
			if( ppos1->level==1&&nest1==0 ){
				ppos1->end=p;
				ppos1->endp=mem+p;fix=0;
				ppos1->level==0;
				if( searchList(temp,not_func)==NULL ){
					(FuncObj[0].val++);
					cpyString(FuncObjPt->name,temp);
					FuncObjPt++;
				}
			}

		}
		p++;
	}
	return FuncObj;
}
Ejemplo n.º 17
0
/* Returns the ith search path from the list as computed by searchList() */
static const char *getSearchPath(int i)
{
	static const char *list = 0;
	static char **path = (char **)0;
	static int end = 0;
	static int numsize = MAX_SEARCH_PATHS;
	static char **tmp;
	/* So we can call free() in the "destructor" we use i=-1 to return the alloc'd array */
	if (i == -1)
	{
		return (const char*)path;
	}
	if (!path)
	{
		path = (char **)calloc(MAX_SEARCH_PATHS, sizeof(char **));
	}
	if (!list && !end)
		list = searchList();
	if (i >= (numsize))
	{
		debug("Increasing size for long PATH");
		tmp = (char **)calloc((MAX_SEARCH_PATHS + numsize), sizeof(char **));
		if (tmp)
		{
			memcpy(tmp, path, sizeof(char **) * numsize);
			free(path);
			path = tmp;
			numsize += MAX_SEARCH_PATHS;
		}
		else
		{
			return 0;
		}
	}

	while (!path[i] && !end)
	{
		path[i] = strsep((char **)&list, ":");

		if (path[i][0] == 0)
			path[i] = 0;
		end = (list == 0);
	}
	return path[i];
}
Ejemplo n.º 18
0
void addToHash(HashTable* t, char* name, double value) {
	int hash = Hash(name);

	if (t->table[hash] == NULL) {
		t->table[hash] = (List*) malloc(sizeof(List));
	}

	List* l = t->table[hash];

	Node* result = searchList(l, name);

	if (result != NULL) {
		// replace original variable's value with new value
		result->variable.value = value;
	} else {
		addTail(l, name, value);
	}
}
Ejemplo n.º 19
0
/* FIXME: Some requests never receive response
Need more tests. When searching automatically AND manually on the same track (same libId),
sometimes one of the responses does not call the slot. Therefore, it should because the requests
and associated QNetworkReply are totally different objects and should not be in conflict.
Maybe related to QNetworkSignalMapper. Also, what is the benefit of having a mapper here ? A simple
QMap<QReply, QString> should be sufficient
*/
void SearchProvider::naturalSearch(QMap<QString, QString> *id_SearchText_Map)
{
    O1Beatport * oauthManager = O1Beatport::instance();
    O1Requestor requestManager(_manager, oauthManager);
    if(!oauthManager->linked()) {
        LOG_ERROR("Unable to perform a search from text, Beatport OAuth is not linked");
        // TODO: emit an error signal
        return;
    }

    QUrl requestUrl(TYM_BEATPORT_API_URL + _searchPath);

    QMapIterator<QString, QString> searchList(*id_SearchText_Map);
    while(searchList.hasNext()) {
        searchList.next();
        QString libId = searchList.key();
        QString text = searchList.value();

        if(text.isEmpty()) return;

        // Replace underscores by spaces (and prevent multiple spaces)
        Utils::instance()->simplifySpaces(text.replace('_', ' '));

        QList<O1RequestParameter> params;
        params << O1RequestParameter("query", text.toLatin1());
        params << O1RequestParameter("facets", "fieldType:track");

        requestUrl.setQuery(QUrlQuery(O1::createQueryParams(params)));
        QNetworkRequest request(requestUrl);

        QNetworkReply *reply = requestManager.get(request, params);

        _naturalSearchMapper->setMapping(reply, libId);
        connect(reply, SIGNAL(finished()),
                _naturalSearchMapper, SLOT(map()));
        connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),
                this, SLOT(requestError(QNetworkReply::NetworkError)));

        LOG_DEBUG(QString("Request sent for search \"%1\"").arg(text));
    }
    delete id_SearchText_Map;
}
Ejemplo n.º 20
0
double getValueForName(HashTable* t, char* name) {
	if (t == NULL || name == NULL)
		return INT_MIN;

	int hash = Hash(name);

	if (hash == -1) {
		return INT_MIN;

	}

	List* l = t->table[hash];

	Node* result = searchList(l, name);

	if (result == NULL)
		return INT_MIN;

	return result->variable.value;
}
Ejemplo n.º 21
0
/**
 * Returns true if word is in dictionary else false.
 */
bool check(const char *word)
{
    // TODO
    /**
     * 0. create a duplicate of word since word pointers to a constant that cannot be modified
     * 1. convert the duplicate to lower case, make it case-insensitive, per specification
     * 2. hash the starting letter to the correct bucket(linked list)
     * 3. search in the correponding bucket
    **/
    
    char temp_dest[strlen(word)+1];
    strcpy(temp_dest, word);
    
    for(int i = 0; temp_dest[i]; i++){
        temp_dest[i] = tolower(temp_dest[i]);
    }
    
    int index = hash(temp_dest[0]);
    //printf("index = %d\n", index);
    if(searchList(d->letter[index], temp_dest))
        return true;
    return false;
}
Ejemplo n.º 22
0
bool HashTable<D>::add(const D & data)
{
  // add the entry to the table
  int index = hash(data);

  if (! table[index].empty() )
    {
      // this is just a performance check
      // cerr << "Warning: collision" << endl;
    }

  itemsByNumber.add(data);

  if ( searchList( table[index], data ) != -1 )
    {
      return false;
    }

  table[ index ].push_back( Node(data, numElements() ));
  numberOfElements++;

  return true;
}
Ejemplo n.º 23
0
/*
 *      bListRemove
 *
 *	Author:	Christian Schafmeister (1991)
 *
 *      Remove an object from the list.
 *      DEREF the object, possible Destroying it if there are
 *      no more references to it.
 *      
 *      Return:
 *              FALSE if the element is not in the list.
 */
BOOL
bListRemove( LIST lList, GENP PPtr )
{
NODEP   *nPPPrev;
NODEP   nPNode;
NODEP	nPPrevious;

                /* If the list is empty then return */

    if ( lList->nPFirstNode==NULL ) return(FALSE);

                /* Search the list for the object */
    nPPPrev = searchList( &(lList->nPFirstNode), (OBJEKT)PPtr, &nPPrevious );
    if ( nPPPrev == NULL ) return(FALSE);

                /* Now actually remove the object from the list */
    nPNode = *nPPPrev;
    (*nPPPrev) = (*nPPPrev)->nPNextNode;

                /* If the node is the last node then update the last node */

    if ( nPNode == lList->nPLastNode ) {
	if ( *nPPPrev == NULL ) lList->nPLastNode = nPPrevious;
	else 			lList->nPLastNode = *nPPPrev;
    }

                /* Destroy the node itself */
    FREE(nPNode);

    CollectionSetSize( lList, iCollectionSize(lList) - 1 );

                /* DEREF the object */

    DEREF( PPtr );

    return(TRUE);
}
Ejemplo n.º 24
0
LinkNode* searchFloatPtrNode(LinkedList* llist, float* data)
{
    return searchList(llist, &data, FLOAT_PTR);
}
Ejemplo n.º 25
0
/* == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == */
int main(int argc, char *argv[])
{
	CDLL list;
	int i,direction, k;
	CDLL_NODE *currNode;

	if (argc < 5)
	{
		printf("You must supply 4 values on the cmd line after %s:\n", argv[0]);
		printf("1: A lowest int value to start the list at.\n");
		printf("2: A highest int value to end the list at.\n");
		printf("3: an integer:  k < hi-lo+1),  indicating that after deleting the selected starting element, k members are skipped before another deletions until all the members are deleted\n");
		printf("4: a string \"CW\" or \"CCW\" for clockwise counter-clockwise. This is the direction\n");
		printf("   you will move as you advance around the ring deleting members\n");
		exit( EXIT_FAILURE );
	}

	k = atoi(argv[3]); /* assume valid int < n */
	if (strcmp(argv[4],"CW")==0)
		direction = CLOCKWISE; /* follow the NEXT ptr */
	else
		direction = COUNTERCLOCKWISE; /* follow the PREV ptr */

	/* Initialize CDLL (set head ptr NULL and set the cmp function */
	initList(&list,compareInt,printInt,freeInt);
	loadList(&list,atoi(argv[1]),atoi(argv[2]));
	printList(list, CLOCKWISE, BRIEF ); /* we follow the NEXT ptr around the ring, not the PREV ptr */

	do /* prompt user for a member to start the counting with */
	{
		int n;
		currNode=NULL;
		printf("\nenter an int  as the starting point in the circle: ");
		fflush(stdout);
		scanf("%d",&n);

		currNode = searchList(list,(void *)n);
	} while (!currNode);

	while (list.head)
	{
		printf("\nDELETING: "); printInt( currNode->data, BRIEF); fflush(stdout);
		currNode = deleteNode(&list,currNode,direction);
		if (!currNode)
		{
			printf("  <-- was the last man standing!\n");
			break;
		}

		printList(list, CLOCKWISE, BRIEF );
		printf("RESUMING AT: "); printInt( currNode->data, BRIEF ); printf(" and skipping %d elements \n", k );
		for ( i=1 ; i<=k ; ++i )
			if (direction==CLOCKWISE)
				currNode = currNode->next;
			else
				currNode=currNode->prev;

	} /* END WHILE - END OF GAME */

    return EXIT_SUCCESS;
}
Ejemplo n.º 26
0
LinkNode* searchLongPtrNode(LinkedList* llist, long* data)
{
    return searchList(llist, &data, LONG_PTR);
}
Ejemplo n.º 27
0
int HashTable<D>::lookup(const D & data) const
{
  int index = hash(data);
  
  return searchList( table[index], data );
}
Ejemplo n.º 28
0
Archivo: D.c Proyecto: jpbat/aed2011
int searchNumber(char* word)
{
    return searchList(list, word, n_lvl);
}
Ejemplo n.º 29
0
// search for IP in list & return filter group on success, -1 on failure
int ipinstance::inList(const uint32_t &ip) {
	if (iplist.size() > 0) {
		return searchList(0, iplist.size(), ip);
	}
	return -1;
}
Ejemplo n.º 30
0
int main(int argc, char** argv){
	FILE *input;
	int c = 0, searchIndex, i;
	char *searchWord;
	LinkedListNodes *listNode;
	
	LinkedLists *list = malloc(sizeof(LinkedLists));
	InitLinkedList(list);
	if(argc ==  2){
		/* Correct number of arguments */
		
		input = fopen(argv[1],"r+");
		if(input != NULL){
			do{
				ElementStructs *element;
				char *word = malloc(80);
				if(!feof(input)){
					fscanf(input, "%s", word);
					element = malloc(sizeof(ElementStructs));
					element->word = word;
					element->index = c;
					AddToBackOfLinkedList(list, element);
					c++;
				}else{
					free(word);
				}
			}while(!feof(input));
			
			printf("Words: %d\n",c);
			
			/* First 6 elements */
			listNode = list->FrontPtr;
			for(i = 0;i < 6;i++){
				printf("%s\n", listNode->ElementPtr->word);
				listNode = listNode->Next;
			}
			
			/* Last 6 elements */
			listNode = list->BackPtr;
			for(i = 0;i < 6;i++){
				printf("%s\n", listNode->ElementPtr->word);
				listNode = listNode->Previous;
			}

			printf("\n-------------------------------------------------------------------\n");		
			searchWord = malloc(80);		
			printf("Please enter the word you would like to search for: ");
			scanf("%s",searchWord);
			
			searchIndex = searchList(list, searchWord);
			if(searchIndex < 0){
				printf("Your string was not found\n");
			}else{
				printf("The string: %s was found at index: %d\n",searchWord,searchIndex);
			}
						
			free(searchWord);			

		}else{
			printf("File: %s could not be opened\n",argv[1]);
			return 2;
		}
		fclose(input);
	}else{
		/* Usage message */
		printf("Usage: %s <input file>\n",argv[0]);
		return 1;
	}
	
	DestroyLinkedList(list);
	free(list);
	return 0;
}