Beginner with Problems creating lists

This is a discussion on Beginner with Problems creating lists within the C++ Programming forums, part of the General Programming Boards category; Hi, I would appreciate your help with the following code. I have to create a list of words and then ...

  1. #1
    Registered User
    Join Date
    Oct 2013
    Location
    Barcelona - Spain
    Posts
    18

    Beginner with Problems creating lists

    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;
    }
    }

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,418
    > On the other hand..any idea to convert in C#.?
    1. C# already has containers for linked lists, which take away all the low level work you have to do in C

    2. If you want it in C#, then the best thing you can do is STOP trawling the web looking for answers and then dumping the half-baked code for someone else to fix.
    ¿Como hacer un programa que cuente las palabras repetidas de un programa en c++? - Yahoo! Respuestas
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems with Lists
    By tphamrick in forum C Programming
    Replies: 4
    Last Post: 09-25-2013, 11:31 AM
  2. Beginner- fgetc, arrays, and singly linked lists
    By timg123 in forum C Programming
    Replies: 5
    Last Post: 07-15-2010, 09:02 AM
  3. Very problems with Lists
    By Yannick in forum C Programming
    Replies: 1
    Last Post: 04-29-2008, 08:36 AM
  4. Help creating lists of pointers
    By The_Kingpin in forum C Programming
    Replies: 2
    Last Post: 12-11-2004, 07:10 PM
  5. Linked lists beginner
    By NightOwl in forum C++ Programming
    Replies: 7
    Last Post: 05-02-2003, 01:30 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21