Visualizzazione dei risultati da 1 a 2 su 2

Discussione: [C++] puntatore this

  1. #1
    Utente di HTML.it
    Registrato dal
    Dec 2009
    Messaggi
    9

    [C++] puntatore this

    è la prima volta che uso il puntatore this..
    ESERCIZIO: Scrivere una funzione che legga una sequenza di numeri
    interi, li inserisca in una lista concatenata, elimini i
    doppioni dalla sequenza, e stampi la sequenza risultante

    non capisco l'errore nella funzione eliminaDoppi:

    codice:
    typedef struct nodo *lista;
    typedef struct nodo{
            int val;
            lista next;
            }nodo;
    
    void eliminaDoppi(lista L)
    {
         lista this = L, prec, temp;
         while (this)
         {
          prec = this;
          while (prec->next)
                {
                temp = prec->next;  
                if (temp->val == this->val)
                         {
                         prec->next = temp->next;
                         free(temp);
                         }
                else prec = prec->next;
                }
           this = this->next;
          }
    }

  2. #2
    Utente di HTML.it L'avatar di shodan
    Registrato dal
    Jun 2001
    Messaggi
    2,381
    this è una parola riservata del cpp. Cambia nome.
    This code and information is provided "as is" without warranty of any kind, either expressed
    or implied, including but not limited to the implied warranties of merchantability and/or
    fitness for a particular purpose.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.