Yes i did the same thing. thanks you guys.
void delete_list(Node *n)
{
Node *tmp = NULL;
// tmp = new Node();
while (n != NULL){
tmp=n->next;
delete (Node *)n;
n=tmp;
}
// delete (Node *)tmp;
}
Now there is no memory leakage. :)
Memcheck, a memory error detector
Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
Command: ./a.out
1 2 3
FILE DESCRIPTORS: 3 open at exit.
Open file descriptor 2: /dev/pts/3
Open file descriptor 1: /dev/pts/3
Open file descriptor 0: /dev/pts/3
HEAP SUMMARY:
in use at exit: 0 bytes in 0 blocks
total heap usage: 5 allocs, 5 frees, 73,776 bytes allocated
All heap blocks were freed -- no leaks are possible
For counts of detected and suppressed errors, rerun with: -v
ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)