Exemple #1
0
int
main() {
	List *list = newList();

	listAddLast(list, "One");
	listAddLast(list, "Two");
	listAddLast(list, "Three");
	listAddFirst(list, "One");
	listAddFirst(list, "Two");
	listAddFirst(list, "Three");

	print_list(list);

	listRemoveFirst(list);
	print_list(list);
	listRemoveLast(list);
	print_list(list);

	listClear(list);
	listAddLast(list, "One");
	listRemoveFirst(list);
	print_list(list);

	listAddFirst(list, "One");
	listAddLast(list, "One");
	listAddFirst(list, "Two");
	listAddLast(list, "Two");
	listAddFirst(list, "Three");
	listAddLast(list, "Three");
	print_list(list);

	deleteList(list);

	return 0;
}
Exemple #2
0
void freeList(LIST *list)
{
  if(list)
  {
    listClear(list);
    free(list);
  }
}
Exemple #3
0
int goc_listListener(GOC_HANDLER uchwyt, GOC_MSG wiesc, void* pBuf, unsigned int nBuf)
{
	if ( wiesc == GOC_MSG_CREATE )
	{
		GOC_StElement* elem = (GOC_StElement*)pBuf;
		GOC_HANDLER* retuchwyt = (GOC_HANDLER*)nBuf;
		GOC_StList* lista = (GOC_StList*)malloc(sizeof(GOC_StList));
		memcpy(lista, elem, sizeof(GOC_StElement));
		*retuchwyt = (GOC_HANDLER)lista;
		goc_systemSendMsg(*retuchwyt, GOC_MSG_INIT, lista, 0);
		return GOC_ERR_OK;
	}
	else if ( wiesc == GOC_MSG_INIT )
	{
		return listInit((GOC_HANDLER)pBuf);
	}
	else if ( wiesc == GOC_MSG_PAINT )
	{
		return goc_listPaint(uchwyt);
	}
	else if ( wiesc == GOC_MSG_FOCUS )
	{
		return listFocus(uchwyt);
	}
	else if ( wiesc == GOC_MSG_FOCUSFREE )
	{
		return listFocusFree(uchwyt);
	}
	else if ( wiesc == GOC_MSG_DESTROY )
	{
		return goc_listDestroy(uchwyt);
	}
	else if ( wiesc == GOC_MSG_LISTSETCOLOR )
	{
		*((GOC_COLOR *)pBuf) = listSetColor( uchwyt, nBuf );
	}
	else if ( wiesc == GOC_MSG_LISTADDTEXT )
	{
		return listAddText(uchwyt, pBuf);
	}
	else if ( wiesc == GOC_MSG_LISTADDROW )
	{
		return listAddRow(uchwyt, pBuf);
	}
	else if ( wiesc == GOC_MSG_LISTCLEAR )
	{
		return listClear(uchwyt);
	}
	else if ( wiesc == GOC_MSG_LISTSETEXTERNAL )
	{
		return listSetExt(uchwyt, pBuf, nBuf);
	}
	return GOC_ERR_UNKNOWNMSG;
}
static void InitDtData(QDP_TYPE_DT_DATA *dt_data)
{
#define QDP_DT_DATA_SIGNATURE "QDP_STRUCT_INIT"

    if (strcmp(dt_data->signature, QDP_DT_DATA_SIGNATURE) == 0) {
        listClear(&dt_data->blist);
    } else {
        listInit(&dt_data->blist);
        sprintf(dt_data->signature, "%s", QDP_DT_DATA_SIGNATURE);
        dt_data->signature[QDP_DT_DATA_SIG_LEN] = 0;
    }

    dt_data->seqno = 0;
    dt_data->used = 0;
}
VOID CloseClientConnection(CLIENT *client)
{

/* If we are breaking this connection, tell the client why */

    if (!client->brkrcvd) iacpSendAlert(client->iacp, client->result);

/* Close the socket and clear the handle */

    iacpClose(client->iacp);
    client->iacp = NULL;
    isiResetIncoming(&client->incoming);
    isiClearDataRequest(&client->datreq);
    client->last.msg.len = 0;
    if (client->last.datreq != NULL) {
        if (client->last.datreq->req.twind != NULL) free(client->last.datreq->req.twind);
        if (client->last.datreq->req.seqno != NULL) free(client->last.datreq->req.seqno);
        client->last.datreq = NULL;
    }
    listClear(&client->history);
}
Exemple #6
0
void listDel(List l) {
    listClear(l);

    free(l);
}
Exemple #7
0
int main(int argc, char* argv[])
{
  sSdlWrapper* wrap = initializeSDLWrapper("Snake", 800, 600, 32, 1, 1);
  game* gameEngine  = initGame(wrap, 32, 24);
  int Selection = 0;
  sTextGFX* startUnsel = createText(wrap, "Start Game", 0xFFFFFFFF);
  sTextGFX* startSel   = createText(wrap, "Start Game", 0xFFFFF000);
  sTextGFX* exitUnsel  = createText(wrap, "Exit Game" , 0xFFFFFFFF);
  sTextGFX* exitSel    = createText(wrap, "Exit Game" , 0xFFFFF000);
  sLinkedList* titleList = 0;
  FILE* titleFile = fopen("snake.pic", "r");
  listInitialize(&titleList, sizeofPoint(), NULL);
  for(int x = 0; x < 32; x++)
    for(int y = 0; y < 24; y++)
      if(x == 0 || x == (31) || y == 0 || y == (23))
      {
	point* toAdd = createPoint(x,y);
	listPushFront(titleList, (void*)toAdd);
	free(toAdd);
      }
  while(isRunning(wrap))
  {
    beginFrame(wrap);
    if(State == -1)
    {
      readTitleFile(titleList, titleFile);
      renderList(titleList, wrap);
    }
    else if(State == 1)
      tick(gameEngine);
    else
    {
      if(Selection == 0)
      {
	renderText(wrap, startSel, 400, 300);
	renderText(wrap, exitUnsel, 400, 325);
      }
      else
      {
	renderText(wrap, startUnsel, 400, 300);
	renderText(wrap, exitSel, 400, 325);
      }
      if(keyDown(wrap, SDLK_DOWN))
	Selection = 1;
      if(keyDown(wrap,SDLK_UP))
	Selection = 0;
      if(keyDown(wrap, SDLK_RETURN))
      {
	if(Selection == 0)
	{
	  State = 1;
	  setupGame(gameEngine);
	}
	else
	  toggleRunning(wrap);
      }
      renderList(titleList, wrap);
    }
    if(keyPressed(wrap, SDLK_ESCAPE))
      toggleRunning(wrap);
    endFrame(wrap);
  }
  listClear(titleList);
  free(titleList);
  destroyText(startUnsel);
  destroyText(startSel);
  destroyText(exitUnsel);
  destroyText(exitSel);
  deinitializeWrapper(wrap);
  destroyGame(gameEngine);
  free(wrap);
  return 0;
}
Route* routeCalculate(int sid1, int sid2, List* stations, List* links)
{
    Station** stationsArray = (Station**)stations->data;
    double* map = (double*)calloc(stations->count, sizeof(double));

    for (int i = 0; i < stations->count; i++) 
    {
        map[i] = -1;
    }

    int found = false;
    int step = false;
    List* currentStations = listNew();
    List* nextStations = listNew();
    listAdd(currentStations, stationsArray[sid2]);
    map[sid2] = 0;


    while (true)
    {
        listClear(nextStations);
        step = false;
        for (int j = 0; j < currentStations->count; j++)
        {
            Station* current = (Station*)currentStations->data[j];

            for (int l = 0; l < current->srtLids->count; l++)
            {
                Link* link = (Link*)current->srtLids->data[l];
                _stepBack(current, link, link->sid2, sid1, map, stationsArray, nextStations, &step, &found);
            }

            for (int l = 0; l < current->endLids->count; l++)
            {
                Link* link = (Link*)current->endLids->data[l];
                _stepBack(current, link, link->sid1, sid1, map, stationsArray, nextStations, &step, &found);
            }
        }
        if (!found && !step) break;

        if (found && nextStations->count == 0) break;
        listClear(currentStations);
        for (int l = 0; l < nextStations->count; l++)
        {
            listAdd(currentStations, nextStations->data[l]);
        }
    }

    listFree(currentStations);
    listFree(nextStations);

    Route* result = NULL;

    if (found)
    {
        found = false;
        Link* nextLink = NULL;
        Station* nextStation = stationsArray[sid1];
        double minval = map[sid1];

        while (!found)
        {
            Station* cursid = nextStation;
            step = false;

            for (int l = 0; l < cursid->srtLids->count; l++)
            {
                Link* link = (Link*)cursid->srtLids->data[l];
                _stepForward(cursid, link, link->sid2, sid2, map, stationsArray, &nextStation, &nextLink, &minval, &step, &found);
            }

            for (int l = 0; l < cursid->endLids->count; l++)
            {
                Link* link = (Link*)cursid->endLids->data[l];
                _stepForward(cursid, link, link->sid1, sid2, map, stationsArray, &nextStation, &nextLink, &minval, &step, &found);
            }

            if (!found && !step) return NULL;

            if (result == NULL)
            { 
                result = _routeNew(stationsArray[sid1]);
            }
            
            result->length += nextLink->len;
            listAdd(result->stations, nextStation);
            listAdd(result->links, nextLink);

            if (found) return result;
        }
    
    }

    routeFree(&result);
    free(map);

    return NULL;
}
Exemple #9
0
void mapDestroy() {
	listClear(&map.minions);
	free(map.tiles);
}
Exemple #10
0
/**
* listDestroy: Deallocates an existing list. Clears all elements by using the
* stored free function.
*
* @param list Target list to be deallocated. If list is NULL nothing will be
* done
*/
void listDestroy( List list ) {
	if ( listClear(list) == LIST_SUCCESS) {
		free( list );
		list = NULL;
	}
}