#include<bits/stdc++.h>
using namespace std;
struct Node
{
int val;
Node*next;
};
Node* InsertAtEnd(Node* root, int x) {
Node* newnode = new Node();
newnode->val = x;
newnode->next = NULL;
if (root == NULL) {
root = newnode;
return root;
}
Node* currnode = root;
while (currnode->next != 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,2);
Print(root);
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKc3RydWN0IE5vZGUKewppbnQgdmFsOwpOb2RlKm5leHQ7Cn07Ck5vZGUqIEluc2VydEF0RW5kKE5vZGUqIHJvb3QsIGludCB4KSB7CiAgICBOb2RlKiBuZXdub2RlID0gbmV3IE5vZGUoKTsKICAgIG5ld25vZGUtPnZhbCA9IHg7CiAgICBuZXdub2RlLT5uZXh0ID0gTlVMTDsKCiAgICBpZiAocm9vdCA9PSBOVUxMKSB7CiAgICAgICAgcm9vdCA9IG5ld25vZGU7ICAKICAgICAgICByZXR1cm4gcm9vdDsKICAgIH0KCiAgICBOb2RlKiBjdXJybm9kZSA9IHJvb3Q7CiAgICB3aGlsZSAoY3Vycm5vZGUtPm5leHQgIT0gTlVMTCkgewogICAgICAgIGN1cnJub2RlID0gY3Vycm5vZGUtPm5leHQ7IAogICAgfQoKICAgIGN1cnJub2RlLT5uZXh0ID0gbmV3bm9kZTsKICAgIHJldHVybiByb290Owp9CnZvaWQgUHJpbnQoTm9kZSpyb290KQp7Ck5vZGUqY3Vycm5vZGU7CmN1cnJub2RlPXJvb3Q7CndoaWxlKGN1cnJub2RlIT1OVUxMKQp7CmNvdXQ8PGN1cnJub2RlLT52YWw8PCIgIjsKY3Vycm5vZGU9Y3Vycm5vZGUtPm5leHQ7Cn0KY291dDw8ZW5kbDsKfQppbnQgbWFpbigpCnsKTm9kZSpyb290PU5VTEw7CnJvb3Q9SW5zZXJ0QXRFbmQocm9vdCw2KTsKcm9vdD1JbnNlcnRBdEVuZChyb290LDIpOwpQcmludChyb290KTsKfQo=