sol4 - COP3530 Solution 4 1. Version 1. a) mergechain(chain...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
COP3530 Solution 4 1. Version 1. a) mergechain(chain a, chain b) { If(a.size==0) { ChainNode currentNode = firstNode; for (int i = 0; i < size; i++) currentNode = currentNode.next; currentNode.next=b.firstNode; size+=b.size; } If(b.size==0) { ChainNode currentNode = firstNode; for (int i = 0; i < size; i++) currentNode = currentNode.next; currentNode.next=a.firstNode; size+=a.size; } If(a.size>0&&b.size>0) { If(a.firstNode.element>b.firstNode.element) { add(size, a.firstNode.element); a.remove(0); mergechain(a,b); } If(!a.firstNode.element>b.firstNode.element) { add(size, b.firstNode.element); b.remove(0); mergechain(a,b); } } Version 2 a) //Java code: package dataStructures;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
public class ChainMerge extends Chain{ ChainNode lastNode = null; public void mergeRec(Chain a,Chain b){ ChainNode pCurrent; int action = 0; if((a.firstNode== null)&&(b.firstNode == null)) { return; } else if((a.firstNode != null)&&(b.firstNode == null)) { action = 0; } else if((a.firstNode == null)&&(b.firstNode != null))
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/15/2010 for the course COP 3530 taught by Professor Davis during the Fall '08 term at University of Florida.

Page1 / 4

sol4 - COP3530 Solution 4 1. Version 1. a) mergechain(chain...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online