<?xml version="1.0" encoding="ISO-8859-1"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Últimas mensagens do tópico "inserir nome e tel,  remover o nome e tel e consultar o tel em tabela hash em c++"]]></title>
		<link>http://www.guj.com.br/posts/list/20.java</link>
		<description><![CDATA[Últimas mensagens enviadas no tópico "inserir nome e tel,  remover o nome e tel e consultar o tel em tabela hash em c++"]]></description>
		<generator>JForum - http://www.jforum.net</generator>
			<item>
				<title>inserir nome e tel,  remover o nome e tel e consultar o tel em tabela hash em c++</title>
				<description><![CDATA[ olá pessoal , pois tenho que fazer um trabalho em c++ pela  tabela hash seria o seguinte : <br /> 1-inserir nomes e telefones de uma pessoa, <br /> 2- depois remover o nome e o telefone e <br /> 3- E  consultar o telefone .<br />  alguém poderia me ajudar por favor. o que consegui fazer foi isso :<br />  eu quero agora implementar o telefone , mais não sei fazer? se alguém souber me ajude por favor! <br /> [code]<br /> #include &lt;stdio.h&gt; <br /> <br /> #include &lt;stdlib.h&gt; <br /> <br /> #include &lt;string.h&gt; <br /> <br /> #define TAMTAB 37 <br /> <br /> <br /> <br /> typedef char string[30]; <br /> <br /> <br /> typedef struct{ <br /> <br /> string tab[TAMTAB]; <br /> <br /> int ocup; <br /> <br /> }tabela; <br /> <br /> <br /> void pausa(){ <br /> <br /> fflush(stdin); <br /> <br /> getchar(); <br /> <br /> } <br /> <br /> <br /> int hash(char *nom){ <br /> <br /> int soma, i; <br /> <br /> soma = 0; <br /> <br /> for(i = 0; i &lt; strlen(nom); i++) <br /> <br /> soma += (i+1)*nom[i]; <br /> <br /> soma = soma%TAMTAB; <br /> <br /> if(soma == 0) <br /> <br /> return 1; <br /> <br /> return soma; <br /> <br /> } <br /> <br /> <br /> int hash_insere(tabela *t, char *nome, int h){ <br /> <br /> if(strcmp(t-&gt;tab[h],"\0") == 0 || strcmp(t-&gt;tab[h], "*") == 0){ <br /> <br /> strcpy(t-&gt;tab[h], nome); <br /> <br /> t-&gt;ocup++; <br /> <br /> printf("\n\tO nome foi inserido na posicao %d\n", h); <br /> <br /> return 0; <br /> <br /> } <br /> <br /> return 1; <br /> <br /> } <br /> <br /> <br /> int hash_procura(tabela *t, char *nome, int h){ <br /> <br /> int i = 0; <br /> <br /> while(strcmp(t-&gt;tab[(h*++i*i)%TAMTAB],"\0") != 0 && strcmp(t-&gt;tab[(h*i*i)%TAMTAB], nome) != 0); //Faz ateh achar um espaco vazio ou achar o nome. <br /> <br /> if(strcmp(t-&gt;tab[(h*i*i)%TAMTAB],"\0") == 0){ <br /> <br /> return -1;//Se nao achou, devolve -1 <br /> <br /> } <br /> <br /> else{ <br /> <br /> printf("\n\tO nome foi encontrado na posição %d\n", h*i*i%TAMTAB); <br /> <br /> return (h*i*i)%TAMTAB; //se achou, em que posicao achou? <br /> <br /> } <br /> <br /> } <br /> <br /> <br /> void hash_remover(tabela *t, char *nome){ <br /> <br /> int a; <br /> <br /> a = hash_procura(t, nome, hash(nome)); <br /> <br /> if(a &lt; 0) <br /> <br /> printf("\n\tO nome %s procurado nao consta na tabela.\n", nome); <br /> <br /> else{ <br /> <br /> strcpy(t-&gt;tab[a], "*"); <br /> <br /> t-&gt;ocup--; <br /> <br /> printf("\n\tO nome foi removido: %s\n", nome); <br /> <br /> } <br /> <br /> } <br /> <br /> <br /> <br /> void menu(){ <br /> <br /> <br /> printf("\t0. Sair do programa\n"); <br /> <br /> printf("\t1. Inserir Nomes;\n"); <br /> <br /> printf("\t2. Procurar Nomes;\n"); <br /> <br /> printf("\t3. Remover Nomes;\n"); <br /> <br /> <br /> <br /> <br /> printf("\n\nSua escolha: "); <br /> <br /> } <br /> <br /> <br /> void escolha(tabela *t){ <br /> <br /> string nome; <br /> <br /> int i, h, opc; <br /> <br /> scanf("%d", &opc); <br /> <br /> switch(opc){ <br /> <br /> case 0: <br /> <br /> break; <br /> <br /> case 1: <br /> <br /> printf("\nDigite os nomes a serem colocados na tabela.\n"); <br /> <br /> printf("Termine a sequencia com \"*\":\n"); <br /> <br /> do{ <br /> <br /> scanf("%s", nome); <br /> <br /> if(strcmp(nome, "*") != 0){ <br /> <br /> i = 0; <br /> <br /> h = hash(nome); <br /> <br /> while(hash_insere(t, nome, ((++i*h*i)%TAMTAB))); <br /> <br /> //printf("i = %d\n", i); //imprimir o numero de tentativas <br /> <br /> } <br /> <br /> }while(strcmp(nome, "*")); //leitura <br /> <br /> break; <br /> <br /> case 2: <br /> <br /> printf("\nDigite os nomes a serem consultados.\n"); <br /> <br /> printf("Termine a sequencia com \"*\"\n"); <br /> <br /> do{ <br /> <br /> scanf("%s", nome); <br /> <br /> if(strcmp(nome, "*") != 0){ <br /> <br /> h = hash(nome); <br /> <br /> i = hash_procura(t, nome,h); <br /> <br /> if(i &lt; 0){ <br /> <br /> printf("\n\tO nome %s nao foi encontrado\n"); <br /> <br /> } <br /> <br /> else{ <br /> <br /> printf("\n\t%s esta na tabela!\n"); <br /> <br /> } <br /> <br /> } <br /> <br /> }while(strcmp(nome, "*"));//procura <br /> <br /> break; <br /> <br /> case 3: <br /> <br /> printf("\nDigite os nomes a serem removidos.\n"); <br /> <br /> printf("Termine a sequencia com \"*\":\n"); <br /> <br /> do{ <br /> <br /> scanf("%s", nome); <br /> <br /> if(strcmp(nome, "*") != 0){ <br /> <br /> hash_remover(t, nome); <br /> <br /> } <br /> <br /> }while(strcmp(nome, "*"));//remocao <br /> <br /> break; <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> default: <br /> <br /> printf("Opcao invalida. Por favor, digite uma opcao valida.\n"); <br /> <br /> break; <br /> <br /> } <br /> <br /> if(opc != 0){ <br /> <br /> menu(); <br /> <br /> escolha(t); <br /> <br /> } <br /> <br /> } <br /> <br /> int main(){ <br /> <br /> tabela t; <br /> <br /> int i; <br /> <br /> for(i = 0; i &lt; TAMTAB; i++){ <br /> <br /> strcpy(t.tab[i],"\0"); <br /> <br /> } <br /> <br /> t.ocup = 0;//Ateh aqui, iniciar tabela. <br /> <br /> menu(); <br /> <br /> escolha(&t); <br /> <br /> printf("Saindo do programa....\n"); <br /> <br /> } <br /> [/code] <br />  <br />   <br />  <br /> ]]></description>
				<guid isPermaLink="true">http://www.guj.com.br/posts/preList/114333/618061.java</guid>
				<link>http://www.guj.com.br/posts/preList/114333/618061.java</link>
				<pubDate><![CDATA[Wed, 7 Jan 2009 16:13:44]]> GMT</pubDate>
				<author><![CDATA[ ADRIANA NUNES]]></author>
			</item>
			<item>
				<title>Re:inserir nome e tel,  remover o nome e tel e consultar o tel em tabela hash em c++</title>
				<description><![CDATA[ Credo, isso é C++? Isso parece mais com C puro e simples. Em C++ eu já tenho pronto o hash (#include &lt;unordered_map&gt; e as strings (#include &lt;string&gt;) e a entrada e saída de dados é normalmente com cout e cin, mas como suponho que o professor recomendou que se implementasse a hash table na mão, vou ficar devendo.<br /> ]]></description>
				<guid isPermaLink="true">http://www.guj.com.br/posts/preList/114333/618067.java</guid>
				<link>http://www.guj.com.br/posts/preList/114333/618067.java</link>
				<pubDate><![CDATA[Wed, 7 Jan 2009 16:24:23]]> GMT</pubDate>
				<author><![CDATA[ thingol]]></author>
			</item>
			<item>
				<title>Re:inserir nome e tel,  remover o nome e tel e consultar o tel em tabela hash em c++</title>
				<description><![CDATA[  teria como me enviar o que vc tem? pelo menos pode me servir.<br /> obrigada]]></description>
				<guid isPermaLink="true">http://www.guj.com.br/posts/preList/114333/618075.java</guid>
				<link>http://www.guj.com.br/posts/preList/114333/618075.java</link>
				<pubDate><![CDATA[Wed, 7 Jan 2009 16:38:36]]> GMT</pubDate>
				<author><![CDATA[ ADRIANA NUNES]]></author>
			</item>
			<item>
				<title>Re:inserir nome e tel,  remover o nome e tel e consultar o tel em tabela hash em c++</title>
				<description><![CDATA[ Acho que não me expressei corretamente. <br /> <br /> Em C++, na biblioteca STL ou na TR1, existem várias coisas prontas; depende só da sua versão do compilador. <br /> <br /> A hash table, por exemplo, pode ser encontrada como stdext::hash_map (Visual Studio 2005 ou posterior) ou std::tr1::unordered_map (Visual Studio 2008); no g++ eu já não sei qual é o nome da classe.<br /> A string, em C++, na STL, é importada usando-se "#include &lt;string&gt;"; "using namespace std" e coisas parecidas.<br /> <br /> Não sei se sua hash table foi corretamente implementada em C; só sei que você precisa, usando sua implementação de hash, incluir o mesmo dado (nome + telefone) em dois hashs, um indexado por nome, e outro indexado por telefone, para atender ao seu requisito. E é por isso que o ideal é criar uma classe que implementa o hash e que receba um parâmetro indicando se você precisa indexar por nome ou telefone; do jeito que você fez (padrão C) está certo, mas é bitolada para o hash por nomes. <br /> ]]></description>
				<guid isPermaLink="true">http://www.guj.com.br/posts/preList/114333/618086.java</guid>
				<link>http://www.guj.com.br/posts/preList/114333/618086.java</link>
				<pubDate><![CDATA[Wed, 7 Jan 2009 17:03:33]]> GMT</pubDate>
				<author><![CDATA[ thingol]]></author>
			</item>
			<item>
				<title>Re:inserir nome e tel,  remover o nome e tel e consultar o tel em tabela hash em c++</title>
				<description><![CDATA[ valeu thingo vou tentar fazer, no caso eu preciso fazer um hash para telefone também né.. um Abração]]></description>
				<guid isPermaLink="true">http://www.guj.com.br/posts/preList/114333/618248.java</guid>
				<link>http://www.guj.com.br/posts/preList/114333/618248.java</link>
				<pubDate><![CDATA[Thu, 8 Jan 2009 07:34:31]]> GMT</pubDate>
				<author><![CDATA[ ADRIANA NUNES]]></author>
			</item>
			<item>
				<title>Re:inserir nome e tel,  remover o nome e tel e consultar o tel em tabela hash em c++</title>
				<description><![CDATA[ olá thingo, será que vc pode me daralguma demonstração de como devo fazer a class para inserir nome e telefone? porque não estou conseguindo fazer.. obrigada]]></description>
				<guid isPermaLink="true">http://www.guj.com.br/posts/preList/114333/620516.java</guid>
				<link>http://www.guj.com.br/posts/preList/114333/620516.java</link>
				<pubDate><![CDATA[Mon, 12 Jan 2009 11:49:56]]> GMT</pubDate>
				<author><![CDATA[ ADRIANA NUNES]]></author>
			</item>
	</channel>
</rss>