Can someone help creating generic linkedlist
without STL
. How do I declare head in main. Is it struct node<>* head ? or struct node* head ? I got a an error using both and it was something like a template declaration cannot appear at block scope
#include <iostream>
using namespace std;
template<class T>
struct node
{
T data;
struct node<T>* next;
};
template<class T>
void Push(struct node<T>** H,T dat)
{
struct node<T> * newnode=(struct node<T> * )malloc(sizeof(struct node<T>)) ;
newnode->data=dat;
newnode->next=*H;
*H=newnode;
}
int main() {
struct node<>* head=NULL;
struct node<>* current;
int a=10;
float f=10.1;
Push<int>(&head,a);
Push<float>(&head,f);
current=head;
while(current)
{
cout<<current->data;
current=current->next;
}
//code
return 0;
}