linked list

Intrebari despre limbajul C++, standardul C++, STL, OOP in C++ sau alte subiecte nelegate de VisualC++
Post Reply
stelian_2681
Junior
Junior
Posts: 36
Joined: 24 Jun 2013, 23:25
Judet: Olt

linked list

Post by stelian_2681 » 02 Jun 2015, 10:28

In codul urmator am o eroare si nu inteleg ce vrea sa spuna eroarea respectiva.

Code: Select all

#include <iostream>
using namespace std;

typedef struct LLSI
{
    int info;
    LLSI *next;
}NODE;

void initNODE(NODE *head, int n);
void addNODE(NODE *head, int n);
void displayNODE(NODE *head);

int main()
{
    NODE *head;
    head = new NODE;
    initNODE(head,10);
    displayNODE(head);
    addNODE(head,20);
    displayNODE(head);
    addNODE(head,30);
    displayNODE(head);
    addNODE(head,40);
    displayNODE(head);
    addNODE(head,50);
    displayNODE(head);
    return 0;
}

void initNODE(NODE *head, int n)
{
    head->info = n;
    head->next =NULL;
}

void addNODE(NODE *head, int n)
{
    NODE *new_node = new NODE;
    new_node->info = n;
    new_node->next = NULL;
    NODE *temp = head;
    while (temp)
    {
        if (temp->next == NULL)
        {
            temp->next = new_node;
            return;
        }
        temp = temp->next;
    }
}

void display(NODE *head)
{
    NODE *temp;
    temp = head;
    cout << endl;
    while (temp)
    {
        cout << " " << temp->info << " ->";
        temp = temp->next;
    }
    cout << " NULL";
    cout << endl;
}



Viorel
Microsoft MVP
Microsoft MVP
Posts: 293
Joined: 13 Jul 2007, 12:26

Re: linked list

Post by Viorel » 03 Jun 2015, 21:02

Probabil eroarea spune să redenumești funcția display în displayNODE.

Post Reply