void insert(T f)
{
Node<T> *temp= new Node<T>(f);
if(first == NULL)
{
first= temp;
curr = temp;
}
else
{
curr->next=temp;
curr = temp;
}
}
void Print(){
if(first == NULL) return;
curr = first;
while( curr )
{
cout << "Value is : "<< curr->date<<endl;
curr = curr->next;
}
}
#include <iostream>
#include <string.h>
using std::cout;
using std::string;
template<typename T>
class List
{
private:
template<class R>
struct Node{
R date;
Node *next;
Node(T t){
date = t;
next = NULL;
}
};
Node<T> *first;
Node<T> *curr;
public:
List(){
first = NULL;
curr = NULL;
}
List(int d)
{
Node<T> *temp= new Node<T>(d);
first = temp;
curr = temp;
}
void insert(T f)
{
Node<T> *temp= new Node<T>(f);
if(first == NULL)
{
first= temp;
curr = temp;
}
else
{
curr->next=temp;
curr = temp;
}
}
void Print(){
if(first == NULL) return;
curr = first;
while( curr )
{
cout << "Value is : "<< curr->date<<endl;
curr = curr->next;
}
}
void DeleteData(int data)
{
Node<T> *delPtr = NULL;
Node<T> *temp = first;
curr = first;
while(curr != NULL && curr->date != data)
{
temp = curr;
curr = curr->next;
}
if(curr == NULL)
{
cout << "this data is not in the list;";
}
else
{
delPtr = curr;
curr = curr->next;
temp->next = curr;
if(delPtr == first)
{
first = first->next;
temp = NULL;
}
delete delPtr;
}
}
};
int main()
{
List<int > ls;
ls.insert(12);
ls.insert(345);
ls.insert(345);
ls.DeleteData(345);
ls.Print();
}
void Print(){
if(first == NULL) return;
curr = first;
while( curr )
{
cout << "Value is : "<< curr->date<<endl;
curr = curr->next;
}
}
void Print(){
if(first == NULL) return;
Node<T> *temp = first;
while( temp )
{
cout << "Value is : "<< temp->date<<endl;
temp = temp->next;
}
}
void Print(){
Node<T> *temp = first;
while( temp )
{
cout << "Value is : "<< temp->date<<endl;
temp = temp->next;
}
}
Citartoma el first pero en la funcion Insert la que se lleno fue curr por que first tiene el link de first, alguien podria explicarme eso por favor.No se si estoy entendiendo muy bien. En la función Print, quieres recorrer toda la lista. Así que, empiezas desde el primer elemento (first), y vas avanzando al siguiente (temp->next) hasta que sea NULL (final de la lista).