Algoritma untuk menyalin semua elemen genap linklist


1.  Algoritma untuk menyalin semua elemen genap linklist
Procedure salin genap(output cnode)
Deskripsi :

pNode copy_list(pNode head) {

  if (!head) return NULL;
for i<-0 to n do
 if (n/2==0)
  pNode node = head, copied = NULL, cnode = NULL;
  for ( ; node; node = node->next->next) {
    cnode = newnode(node->next, node->data);
    cnode->other = node->other;
    if (node == head)
      copied = cnode;


    node->next = cnode;  
    node -> cnode -> (orig)node->next
  }

  for (node = head; node && node->next;
       node = node->next->next
    if (node->other)
      node->next->other = node->other->next;
    else
      node->next->other = NULL;  

  // restore lists
  node = head; cnode = copied;
  for ( ; cnode && cnode->next; node = node->next, cnode = cnode->next) {
    node->next = node->next->next;
    cnode->next = cnode->next->next;
  }
  node->next = NULL;

Posting Komentar

0 Komentar