Hi,
I would appreciate your help with the following code. I have to create a list of words and then when one is repeated the program has to show with a message.
Can you help me with depuration and where is the problem. Lot of hours lost and nothing.
Thanks in advance,
Toni
"Sorry but the program is in spanish"
On the other hand..any idea to convert in C#.?
Code:
#include <vcl.h>
#include <iostream.h>
#include <conio.h>
#include <string.h>
#pragma hdrstop
class rep{
public:
string palabra;
int repet;
rep *next;
};
rep *list=NULL,*last=NULL;
void crea_nodo(int);
void muestra_repeticiones();
void terminar();
void nodo(string);
//------------------------------------…
#pragma argsused
int main(int argc, char* argv[])
{
int n;
clrscr();
cout<<"¿Cuantas palabras vas a ingresar?"<<endl;
cin>>n;
cout<<endl<<endl;
crea_nodo(n);
muestra_repeticiones();
terminar();
return 0;
}
//------------------------------------…
void crea_nodo(int n){
string g;
bool repe=false;
rep *aux;
while(n>0){
cin>>g;
if(list==NULL){
nodo(g);
}else{
aux=list;
repe=false;
while(aux!=NULL && !repe){
if(aux->palabra==g){
aux->repet++;
repe=true;
}
aux=aux->next;
}
if(!repe) nodo(g);
}
n--;
}
}
//------------------------------------…
void muestra_repeticiones(){
rep *aux=list;
cout<<endl<<endl;
while(aux!=NULL){
cout<<aux->palabra<<'\t'<<aux->repet<<" repeticiones"<<endl;
aux=aux->next;
}
getch();
}
//------------------------------------…
void terminar(){
rep *del=list;
while(del!=NULL){
list=list->next;
del->next=NULL;
delete del;
del=list;
}
}
//------------------------------------…
void nodo(string g){
rep *nuevo=new rep;
nuevo->next=NULL;
nuevo->palabra=g;
nuevo->repet=1;
if(list==NULL){
list=nuevo;
last=nuevo;
}else{
last->next=nuevo;
last=nuevo;
}
}