A
A
Andrey2018-10-18 16:57:31
C++ / C#
Andrey, 2018-10-18 16:57:31

How to move an element to the end of a singly-directed list?

I tried in different ways, but I can’t cope with the links :(
It seems that I understand in my head what is wrong and what needs to be done, but I can’t implement it.
Please help. Thank you :)

PS Functions for deleting, inserting, etc., if necessary, I will provide!

insertAfterList - the function adds the specified element to the end of the list.
deleteList - removes from the list by key (key)
nd = lst->head;
  nd1 = lst->head;

  for (i = 0; nd != lst->tail; i++) {
    j = 0;
    nd1 = nd->next;
    for (; nd1 != lst->tail; j++) {
      if ((nd1->info == nd->info) && (nd1->key != nd->key)) {

        insertAfterList(lst, nd1, nd1->key);
        deleteList(lst, nd1->key);

      }
      if (nd1->next != NULL)
        nd1 = nd1->next; 
    }
    nd = nd->next;
  }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question