What is the error in the code,as its showing 0 as output.
K append(linked list)
- you cant use “0” as a NULL character. 0 is a different character with a unique ASCII value.
- In the display function you are printing the value of temp->next instead of temp->val which will give you addresses of nodes instead of values. (address of NULL is 0, hence the output)
- Your code will fail in case k > n
The reason your kappend function is failing is because of the condition in your while loop. Initially count = 1 and your condition will fail and the while loop will not be executed so make it!=instead of== - I’d also suggest you to use classes instead of structures and not to use global variables, especially when dealing with pointers.
- https://ide.codingblocks.com/s/231449 I fixed all the functions except kappend here, i am leaving that to you. If you have any trouble with that I’ll be happy to help!