import java.util.Queue; import java.util.Stack; /* * SD2x Homework #2 * Implement the method below according to the specification in the assignment description. * Please be sure not to change the method signature! */ public class HtmlValidator { public static Stack isValidHtml(Queue tags) { Stack matchedTags = new Stack(); while(!tags.isEmpty()){ HtmlTag tag = tags.remove(); if(tag.isSelfClosing()){ continue; } if(tag.isOpenTag()){ matchedTags.push(tag); }else{ if(matchedTags.isEmpty()){ return null; } if(tag.matches(matchedTags.peek())){ matchedTags.pop(); }else{ if( matchedTags.isEmpty() ){ return null; } break; } } } return matchedTags; } }