What is the problem with my code

Hello @Parmeet-Kalsi-1631789033630118,

I have corrected your code:

Hope, this would help.

Hey @Parmeet-Kalsi-1631789033630118,

You have reopened the doubt.

Do, you wanna ask something?

I understood the mistake in my code but i have one query i.e for the most basic tasks like insertion of elements in my list and printing the list i had to define every function everytime even though these functions are already defined in stl. So do we have to do it everytime or there is a way to escape from this.

Hey @Parmeet-Kalsi-1631789033630118,

What you can do here is to create your own header file and write all these basic codes inside that and then just include those header files in your code.
This is how you do in corporate world.
Refer this:

But, here as you have to submit your codes to the IDE. So, you have to write these the each time,

Thanks i understood it now so it means that stl can’t help ,
And from your experience does writing the basic functions every time creates a problem when doing some higher level or i must say interview level questions.

Please reply my question. …

Hello @Parmeet-Kalsi-1631789033630118,

No,they don’t.
If you are sitting in an interview.
You might be asked to skip those basic function.
While sometimes you have to write the entire code.

So, it depends upon the requirements.
STL do helps.

As you need not to the code for insertion.
There are functions like push and insert that you can directly use to insert the elements.

I understood it ,
Please tell that can we solve this k append problem using stl containers and if yes then how??

Hey @Parmeet-Kalsi-1631789033630118,

Not with list STL.
As you cannot change the links i.e. the next of one element to another.
You don’t have any such function available in the STL.