K append(linked list)


What is the error in the code,as its showing 0 as output.

@aditi2512201012019

  1. you cant use “0” as a NULL character. 0 is a different character with a unique ASCII value.
  2. 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)
  3. 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 ==
  4. I’d also suggest you to use classes instead of structures and not to use global variables, especially when dealing with pointers.
  5. 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!