Print a single node

0

I have a linked list where each node contains information of a computer equipment ie brand, processor, etc. leaving something like this:

Node1: Brand, processor, color.

Node2.Marca processor, color.

struct nodo{
              string marca;
              string procesador;
              struct nodo *sgte;
};

void insertar(Milista &lista, string marca, String procesador)
{

    Milista q;
    q = new(struct nodo);
    q->marca=marca;
    q->procesador procesador;
    q->sgte = lista;
    lista  = q;
}

and I have my function that prints it

void reportarLista(Milista lista)
{
     int i = 0;

     while(lista != NULL)
     {
          cout << lista->marca << lista->procesador << endl;
          lista = lista->sgte;
          i++;
     }
}

There is some way to print a node in specific, I mean something similar to when you print an arrangement in such a position, that is, partially print the list.

Thanks

    
asked by Juan 16.04.2018 в 01:27
source

1 answer

0

In ReportList you could add another argument that is the name of the brand you are looking for, then in the while you do an if to compare the Brand of the current node with the name of the brand that you passed as an argument , if it's the same, you print it, outside of if you put the list = list-> stge

void reportarLista(Milista lista, string nomMarca){
   while(lista!=NULL){
      if (lista->marca==nomMarca){
         cout<<lista->marca<<lista->procesador<<endl;
      lista=lista->sgte;
}
    
answered by 16.04.2018 в 01:52