예제 #1
0
파일: heap.c 프로젝트: FEUP-MIEEC/Prog2
int heap_insere(heap * h, const char * texto, int prioridade)
{
	elemento * aux, * elem;
	int i;

	/* se heap esta' cheia, nao insere elemento */
	if (h->tamanho_atual >= h->tamanho_maximo)
		return 0;

	elem = elemento_cria(prioridade, texto);
	if (!elem)
		return 0;

	/* coloca elemento no fim da heap */
	i = h->tamanho_atual;
	h->elementos[i] = elem;
	h->tamanho_atual++;
	
	/* enquanto elemento for mais prioritario do que o respetivo pai, troca-os */
	while (i != RAIZ && menor_que(h->elementos[i], h->elementos[PAI(i)]))
	{
		aux = h->elementos[PAI(i)];
		h->elementos[PAI(i)] = h->elementos[i];
		h->elementos[i] = aux;
		i = PAI(i);
	}
	return 1;
}
예제 #2
0
// Insere no final,
// verifica se o ancestral tem prioridade menor que o inserido,
// se sim: swap
// senão: pára.
static short _enfileirar(TTAD* t, void* elemento){
  TDadoTAD *d = t->dado;
  if(!elemento || !d) return 0;

  int posInsercao = d->ocupacao, i;
  int posAncestral = PAI(posInsercao);
  void *elementoAncestral;

  TArrayDinamico *vet = d->vetorFila;
  unsigned tam = vet->tamanho(vet);

  if(posInsercao >= tam){
    ajustarAD(vet, tam * 2);
    t->sobrecarga++;
  }

  vet->atualizar(vet, posInsercao, elemento);
  d->ocupacao++;

  for(i=posInsercao; (i > 0)
    && COMPARAR_PRIORIDADES(elemento, vet->acessar(vet,posAncestral)); ){
      vet->atualizar(vet, i, vet->acessar(vet, posAncestral));
      vet->atualizar(vet, posAncestral, elemento);

      // elementoAncestral = vet->acessar(vet, posAncestral);
      // vet->atualizar(vet, posAncestral, elemento);
      // vet->atualizar(vet, i, elementoAncestral);

      t->movimentacoes_enfileirar++;
      i = posAncestral;
      posAncestral = PAI(i);
  }

  return 1;
}
예제 #3
0
static void Subir (BRTOS_TIMER* timers,INT8U i) {
     while (i > 1 && timers[PAI(i)]->timeout > timers[i]->timeout)
     {
         void* tmp = timers[PAI(i)];
         timers[PAI(i)] = timers[i];
         timers[i] = tmp;
         i=PAI(i);
     }
}
예제 #4
0
파일: heap.c 프로젝트: FEUP-MIEEC/Prog2
void mostraHeap(heap *h, int indice)
{
	int i, nivel = 0;
	
	if (indice < h->tamanho_atual) 
	{
		i = indice;
		while(i > RAIZ)
		{
			i = PAI(i);
			nivel++;
		}
	
		mostraHeap(h, FILHO_ESQ(indice));

		for(i = 0; i < 3 * nivel; i++)			
			printf("     ");

		printf("%s (%d)\n",h->elementos[indice]->valor, h->elementos[indice]->prioridade);
		
		mostraHeap(h, FILHO_DIR(indice));
	}
	
	if (nivel == 0) 
		printf("\n");
}
예제 #5
0
int CMyListBox::GetItemTextL(lua_State* L)
{
	CString strText;
	this->GetText(PAI(L, 1), strText);
	lua_pushstring(L, strText);
	return 1;
}
예제 #6
0
int CMyListBox::DeleteItemL(lua_State* L)
{
	int nParams = lua_gettop(L);
	if(lua_istable(L, 1))
	{		
		lua_pushnil(L);
		while(lua_next(L, -2) != 0)
		{
			DeleteString(PAI(L, -1));
			lua_pop(L, 1);
		}
		lua_pop(L, 1);
	}
	else
	{
		DeleteString(PAI(L, -1));	
	}
	return 0;
}
예제 #7
0
int heap_insere(heap * h, char * texto, int prioridade)
{
	elemento * aux, * elem;
	int i;

	if (h->tamanho_actual >= h->tamanho_maximo)
		return 0;

	elem = elemento_cria(prioridade, texto);

	i = h->tamanho_actual;
	h->elementos[i] = elem;
	h->tamanho_actual++;
	while (i != RAIZ && menor_que(h->elementos[i], h->elementos[PAI(i)])) {
		aux = h->elementos[PAI(i)];
		h->elementos[PAI(i)] = h->elementos[i];
		h->elementos[i] = aux;
		i = PAI(i);
	}
	return 1;
}
예제 #8
0
int CMyListBox::AddStringL(lua_State* L)
{
	if(lua_istable(L, 1))
	{
		int nTop = lua_gettop(L);
		lua_pushnil(L);
		while(lua_next(L, -2) != 0)
		{
			AddString(PAS(L, -1));
			lua_pop(L, 1);
		}
		lua_pop(L, 1);
	}
	else if(lua_isnumber(L, 1) && !lua_isnoneornil(L, 2))
	{
		InsertString(PAI(L, 1), PAS(L, 2));
	}
	else
	{
		AddString(PAS(L, 1));
	}
	return 0;
}
예제 #9
0
int CFlashCtrl::LoadMovieL(lua_State* L)
{
	m_flashCtrl.LoadMovie(PAI(L, 2), PAS(L, 1));
	m_flashCtrl.Play();
	return 0;
}
예제 #10
0
int ListBoxType::Attribute(void* pControl, lua_State* L, BOOL bGet, BOOL& bHandled)
{
	CMyListBox* pList = ChangeControlType(pControl);
	if(pList == NULL)
	{
		bHandled = FALSE;
		return 0;
	}

	bHandled = TRUE;
	CString strName = PAS(L, 1);	
	const char* pszName = PAS(L, 1);\
	//以下是处理控件属性,如果处理了,直接返回,否则不做操作
	if(strName == "count")
	{
		if(bGet)
		{
			lua_pushnumber(L, pList->GetCount());
			return 1;
		}
	}
	else if(strName == "cursel")
	{
		if(bGet)
		{
			lua_pushnumber(L, pList->GetCurSel());
			return 1;
		}
		else
		{
			lua_pushnumber(L, pList->SetCurSel(PAI(L, 2)));
			return 1;
		}
	}
	else if(strName == "topindex")
	{
		if(bGet)
		{
			lua_pushnumber(L, pList->GetTopIndex());
			return 1;
		}
		else
		{
			lua_pushnumber(L, pList->SetTopIndex(PAI(L, 2)));
			return 1;
		}
	}
	else if(strName == "item-height")
	{
		if(bGet)
		{
			lua_pushnumber(L, pList->GetItemHeight(0));
			return 1;
		}
	}
	else if(strName == "dir")
	{
		if(bGet)
		{

		}
		else
		{
			pList->Dir(DDL_HIDDEN | DDL_READONLY | DDL_DIRECTORY, PAS(L, 2));
			return 0;
		}
	}

	bHandled = FALSE;
	return 0;

}
예제 #11
0
int CMyListBox::SetCurSelL(lua_State* L)
{
	lua_pushnumber(L, SetCurSel(PAI(L, 1)));
	return 1;
}