Torna indietro   Hardware Upgrade Forum > Software > Programmazione

DJI Osmo Pocket 4: la gimbal camera tascabile cresce e ha nuovi controlli fisici
DJI Osmo Pocket 4: la gimbal camera tascabile cresce e ha nuovi controlli fisici
DJI porta un importante aggiornamento alla sua linea di gimbal camera tascabili con Osmo Pocket 4: sensore CMOS da 1 pollice rinnovato, gamma dinamica a 14 stop, profilo colore D-Log a 10 bit, slow motion a 4K/240fps e 107 GB di archiviazione integrata. Un prodotto pensato per i creator avanzati, ma che convince anche per l'uso quotidiano
Sony INZONE H6 Air: il primo headset open-back di Sony per giocatori
Sony INZONE H6 Air: il primo headset open-back di Sony per giocatori
Il primo headset open-back della linea INZONE arriva a 200 euro con driver derivati dalle cuffie da studio MDR-MV1 e un peso record di soli 199 grammi
Nutanix cambia pelle: dall’iperconvergenza alla piattaforma full stack per cloud ibrido e IA
Nutanix cambia pelle: dall’iperconvergenza alla piattaforma full stack per cloud ibrido e IA
Al .NEXT 2026 di Chicago, Nutanix ha mostrato quanto sia cambiata: una piattaforma software che gestisce VM, container e carichi di lavoro IA ovunque, dall’on-premise al cloud pubblico. Con un’esecuzione rapidissima sulle partnership e sulla migrazione da VMware
Tutti gli articoli Tutte le news

Vai al Forum
Rispondi
 
Strumenti
Old 24-01-2006, 22:49   #1
D4rkAng3l
Bannato
 
Iscritto dal: Mar 2004
Città: Roma
Messaggi: 2688
[C]aiutino liste

Ciao,
mi date una mano a capire questo codice?l'anno scorso avevo capito le liste grazie al libro della McRownhill che festisce le funzioni in modo completamente diverso rispetto al Deitel...questo è un codice della deitel...non sono mai riuscito a capirlo bene e stò rosicando:

Le cose che non capisco sono quei maledetti typedef...lo sò che sono una strunzata ma in questo caso che fanno?

Io ho un tipo di dato chiaato listNode che contiene un dato di tipo char e il puntatore al prossimo nodo della lista di tipo struct listNode

typedef struct listNode LISTNODE; dovrebbe semplicemente rinominarmi il tipo struct listNode in LISTNODE tutto maiuscole per accorciare il nome ed evitare di dover scrivere struct listNode tutte le volte?

typedef LISTNODE *LISTNODEPTR; questo che cavolo fà invece?

Grazie
Andrea

Codice:
/* Operating and maintaining a list */
#include <stdio.h>
#include <stdlib.h>

struct listNode {  /* self-referential structure */
   char data;
   struct listNode *nextPtr;
};

typedef struct listNode LISTNODE;
typedef LISTNODE *LISTNODEPTR;

void insert(LISTNODEPTR *, char);
char Delete(LISTNODEPTR *, char);
int isEmpty(LISTNODEPTR);
void printList(LISTNODEPTR);
void instructions(void);

main()
{
   LISTNODEPTR startPtr = NULL;
   int choice;
   char item;

   instructions();  /* display the menu */
   printf("? ");
   scanf("%d", &choice);

   while (choice != 3) {

      switch (choice) {
         case 1:
            printf("Enter a character: ");
            scanf("\n%c", &item);
            insert(&startPtr, item);
            printList(startPtr);
            break;
         case 2:
            if (!isEmpty(startPtr)) {
               printf("Enter character to be deleted: ");
               scanf("\n%c", &item);

               if (Delete(&startPtr, item)) {
                  printf("%c deleted.\n", item);
                  printList(startPtr);
               }
               else
                  printf("%c not found.\n\n", item);
            }
            else
               printf("List is empty.\n\n");

            break;
         default:
            printf("Invalid choice.\n\n");
            instructions();
            break;
      }

      printf("? ");
      scanf("%d", &choice);
   }

   printf("End of run.\n");
   return 0;
}

/* Print the instructions */
void instructions(void)
{
   printf("Enter your choice:\n"
          "   1 to insert an element into the list.\n"
          "   2 to delete an element from the list.\n"
          "   3 to end.\n");
}

/* Insert a new value into the list in sorted order */
void insert(LISTNODEPTR *sPtr, char value)
{
   LISTNODEPTR newPtr, previousPtr, currentPtr;
  
   newPtr = (LISTNODEPTR)malloc(sizeof(LISTNODE)); /* ho aggiunto un cast */
    
   if (newPtr != NULL) {    /* is space available */
      newPtr->data = value;
      newPtr->nextPtr = NULL;

      previousPtr = NULL;
      currentPtr = *sPtr;

      while (currentPtr != NULL && value > currentPtr->data) {
         previousPtr = currentPtr;          /* walk to ...   */
         currentPtr = currentPtr->nextPtr;  /* ... next node */
      }

      if (previousPtr == NULL) {
         newPtr->nextPtr = *sPtr;
         *sPtr = newPtr;
      }
      else {
         previousPtr->nextPtr = newPtr;
         newPtr->nextPtr = currentPtr;
      }
   }
   else
      printf("%c not inserted. No memory available.\n", value);
}

/* Delete a list element */
char Delete(LISTNODEPTR *sPtr, char value)
{
   LISTNODEPTR previousPtr, currentPtr, tempPtr;

   if (value == (*sPtr)->data) {
      tempPtr = *sPtr;
      *sPtr = (*sPtr)->nextPtr;  
      free(tempPtr);             
      return value;
   }
   else {
      previousPtr = *sPtr;
      currentPtr = (*sPtr)->nextPtr;

      while (currentPtr != NULL && currentPtr->data != value) {
         previousPtr = currentPtr;          /* walk to ...   */
         currentPtr = currentPtr->nextPtr;  /* ... next node */
      }

      if (currentPtr != NULL) {
         tempPtr = currentPtr;
         previousPtr->nextPtr = currentPtr->nextPtr;
         free(tempPtr);
         return value;
      }                                                        
   }

   return '\0';
}

/* Return 1 if the list is empty, 0 otherwise */
int isEmpty(LISTNODEPTR sPtr)
{
   return sPtr == NULL;
}

/* Print the list */
void printList(LISTNODEPTR currentPtr)
{
   if (currentPtr == NULL)
      printf("List is empty.\n\n");
   else {
      printf("The list is:\n");

      while (currentPtr != NULL) {
         printf("%c --> ", currentPtr->data);
         currentPtr = currentPtr->nextPtr;
      }

      printf("NULL\n\n");
   }
}
D4rkAng3l è offline   Rispondi citando il messaggio o parte di esso
Old 25-01-2006, 13:25   #2
Guts
Senior Member
 
L'Avatar di Guts
 
Iscritto dal: May 2003
Città: Milano
Messaggi: 2894
anche il mio libro usa quel typedef, serve a creare il tipo LISTNODEPTR come puntatore a LISTNODE. nn ha un'utilità particolare ti evita solo qualche asterisco, imho è inutile, ma magari ha qualche funzione che ancora nn ho capito
__________________
P4 2.8 NorthwoodC - 2x256 vitesta ddr500 + 1GB Kingston ddr400 - P4C800-Deluxe - SAPPHIRE Radeon X1950pro 512MB AGP - Samsung 931BW
 Macbook Alu
Guts è offline   Rispondi citando il messaggio o parte di esso
Old 25-01-2006, 13:28   #3
kk3z
Senior Member
 
L'Avatar di kk3z
 
Iscritto dal: Nov 2003
Messaggi: 980
Non c'era bisogno di postare tutto il codice, quel typedef definisce un puntatore alla struttura, è la stessa cosa di
Codice:
typedef struct listNode *LISTNODEPTR;
Tutto può essere ridotto a
Codice:
typedef struct listNode {  /* self-referential structure */
   char data;
   struct listNode *nextPtr;
} LISTNODE, *LISTNODEPTR;
kk3z è offline   Rispondi citando il messaggio o parte di esso
 Rispondi


DJI Osmo Pocket 4: la gimbal camera tascabile cresce e ha nuovi controlli fisici DJI Osmo Pocket 4: la gimbal camera tascabile cr...
Sony INZONE H6 Air: il primo headset open-back di Sony per giocatori Sony INZONE H6 Air: il primo headset open-back d...
Nutanix cambia pelle: dall’iperconvergenza alla piattaforma full stack per cloud ibrido e IA Nutanix cambia pelle: dall’iperconvergenza alla ...
Recensione Xiaomi Pad 8 Pro: potenza bruta e HyperOS 3 per sfidare la fascia alta Recensione Xiaomi Pad 8 Pro: potenza bruta e Hyp...
NZXT H9 Flow RGB+, Kraken Elite 420 e F140X: abbiamo provato il tris d'assi di NZXT NZXT H9 Flow RGB+, Kraken Elite 420 e F140X: abb...
La NASA ha confermato il supporto per il...
Sierra Space ha completato il test acust...
Ryzen 7 5800X3D pronto a tornare sul mer...
NASA: l'amministrazione Trump prosegue s...
L'Iran avrebbe acquistato un satellite p...
VivaTech compie dieci anni e raddoppia p...
Le vendite di CPU si sono ridotte di 25 ...
Starship: SpaceX ha completato lo static...
Huawei FusionSolar Roadshow 2026: l'inno...
Nuovo trailer per Street Fighter: un fil...
Sovranità sui dati: arriva la pri...
Schede video NVIDIA e AMD di nuovo su Ma...
Robot aspirapolvere, TV OLED, iPhone 17 ...
EUREKA J15 Pro Ultra super interessante ...
Intel porta l'AI nei notebook entry-leve...
Chromium
GPU-Z
OCCT
LibreOffice Portable
Opera One Portable
Opera One 106
CCleaner Portable
CCleaner Standard
Cpu-Z
Driver NVIDIA GeForce 546.65 WHQL
SmartFTP
Trillian
Google Chrome Portable
Google Chrome 120
VirtualBox
Tutti gli articoli Tutte le news Tutti i download

Strumenti

Regole
Non Puoi aprire nuove discussioni
Non Puoi rispondere ai messaggi
Non Puoi allegare file
Non Puoi modificare i tuoi messaggi

Il codice vB è On
Le Faccine sono On
Il codice [IMG] è On
Il codice HTML è Off
Vai al Forum


Tutti gli orari sono GMT +1. Ora sono le: 21:59.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Served by www3v