#include
using namespace std;
struct node
{
int value;
node* next;
};
class LinkedList
{
private:
node* root;
node* tail;
public:
LinkedList(int value_temp)
{
root = new node;
root->value = value_temp;
}
void insert_end(int value_temp);
void print();
~LinkedList()
{
node *node_temp=root,*node_pre = NULL;
while(node_temp)
{
node_pre = node_temp;
node_temp = node_temp->next;
delete node_pre;
}
}
};
void LinkedList::print()
{
node* node_temp=root;
while(node_temp)
{
cout<value<<",";
node_temp = node_temp->next;
}
cout<}
void LinkedList::insert_end(int value_temp)
{
node* node_new = new node;
node_new->value = value_temp;
node_new->next = NULL;
if(root == NULL)
{ root = node_new;
return;
}
node* node_temp = root;
while(node_temp->next)
node_temp = node_temp->next;
node_temp->next = node_new;
}
int main()
{
LinkedList List(4),List2(6);
List.insert_end(5);
List2.insert_end(8);
List.print();
List2.print();
}
using namespace std;
struct node
{
int value;
node* next;
};
class LinkedList
{
private:
node* root;
node* tail;
public:
LinkedList(int value_temp)
{
root = new node;
root->value = value_temp;
}
void insert_end(int value_temp);
void print();
~LinkedList()
{
node *node_temp=root,*node_pre = NULL;
while(node_temp)
{
node_pre = node_temp;
node_temp = node_temp->next;
delete node_pre;
}
}
};
void LinkedList::print()
{
node* node_temp=root;
while(node_temp)
{
cout<
node_temp = node_temp->next;
}
cout<
void LinkedList::insert_end(int value_temp)
{
node* node_new = new node;
node_new->value = value_temp;
node_new->next = NULL;
if(root == NULL)
{ root = node_new;
return;
}
node* node_temp = root;
while(node_temp->next)
node_temp = node_temp->next;
node_temp->next = node_new;
}
int main()
{
LinkedList List(4),List2(6);
List.insert_end(5);
List2.insert_end(8);
List.print();
List2.print();
}
No comments :
Post a Comment