#include<bits/stdc++.h>
using namespace std;
struct Node{
int val;
Node*next;
};
Node*InsertAtEnd(Node*root,int x)
{
Node*newnode=new Node();
newnode->next=NULL;
newnode->val=x;
if(root==NULL)
{
root=newnode;
return root;
}
else
{
newnode->next=root;
root=newnode;
return root;
}
Node*currnode;
currnode=root;
while(currnode!=NULL)
{
currnode=currnode->next;
}
currnode->next=newnode;
return root;
}
void Print(Node*root)
{
Node*currnode;
currnode=root;
while(currnode!=NULL)
{
cout<<currnode->val<<" ";
currnode=currnode->next;
}
cout<<endl;
}
int main()
{
Node*root=NULL;
root=InsertAtEnd(root,6);
root=InsertAtEnd(root,8);
root=InsertAtEnd(root,1);
Print(root);
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKc3RydWN0IE5vZGV7CmludCB2YWw7Ck5vZGUqbmV4dDsKfTsKTm9kZSpJbnNlcnRBdEVuZChOb2RlKnJvb3QsaW50IHgpCnsKTm9kZSpuZXdub2RlPW5ldyBOb2RlKCk7Cm5ld25vZGUtPm5leHQ9TlVMTDsKbmV3bm9kZS0+dmFsPXg7CmlmKHJvb3Q9PU5VTEwpCnsKcm9vdD1uZXdub2RlOwpyZXR1cm4gcm9vdDsKfQplbHNlCnsKbmV3bm9kZS0+bmV4dD1yb290Owpyb290PW5ld25vZGU7CnJldHVybiByb290Owp9Ck5vZGUqY3Vycm5vZGU7CmN1cnJub2RlPXJvb3Q7CndoaWxlKGN1cnJub2RlIT1OVUxMKQp7CmN1cnJub2RlPWN1cnJub2RlLT5uZXh0Owp9CmN1cnJub2RlLT5uZXh0PW5ld25vZGU7CnJldHVybiByb290Owp9CnZvaWQgUHJpbnQoTm9kZSpyb290KQp7Ck5vZGUqY3Vycm5vZGU7CmN1cnJub2RlPXJvb3Q7CndoaWxlKGN1cnJub2RlIT1OVUxMKQp7CmNvdXQ8PGN1cnJub2RlLT52YWw8PCIgIjsKY3Vycm5vZGU9Y3Vycm5vZGUtPm5leHQ7Cn0KY291dDw8ZW5kbDsKfQppbnQgbWFpbigpCnsKTm9kZSpyb290PU5VTEw7CnJvb3Q9SW5zZXJ0QXRFbmQocm9vdCw2KTsKcm9vdD1JbnNlcnRBdEVuZChyb290LDgpOwpyb290PUluc2VydEF0RW5kKHJvb3QsMSk7ClByaW50KHJvb3QpOwp9Cg==