Сравнение объектов в стеках и очередях - PullRequest
0 голосов
/ 12 апреля 2020

В этом проекте я пытаюсь создать стек и очередь для доступа к тегам HTML. Так например <&>. В этом проекте я пытаюсь получить доступ к удаленному тегу> и добавить его в стек. Часть, в которой я запутался, - как бы я go сравнил тег> с последним тегом, добавленным в стек? Кроме того, как бы я сравнил объекты в стеке и очереди?

Queue<String> tagQueue = new LinkedList<String>();
    LinkedStack<String> tagStack = new LinkedStack<String>();
    String[] tags = null;
    String txt = "";
    int i;
    int tag = tags.length;

    try {
        Scanner s = new Scanner(new File(filename));
        while (s.hasNextLine()) {
            txt = txt + s.nextLine();      
        }
// Part One will go through the file if an HTML tag is encountered
        // it will grab the tag and place it into a LinkedQueue
        for (i = 0; i < tag; i++) {
            if (tags[i].startsWith("<") || tags[i].startsWith(">")) {
                tagQueue.add(tags[i]);
            }     
        }

        // Part Two will utilize the tags gained from the first portion
        // and remove them one by one from the LinkedQueue
        while (!tagQueue.isEmpty()) {
            if (tags[i].startsWith("<") || tags[i].startsWith(">")) {
                tagQueue.remove();

            }

        // Part Three will take an open tag removed from the Queue and add
        // it to the LinkedStack
            String qPeek = tagQueue.peek();
            if (qPeek.startsWith("<")) {
            tagStack.push(tags[i]);
        }

        // Part Four will access a closing tag and compare it to the last one
        // added to the stack, if the open tag from the stack, and the
        // closing tag from the queue match, continue, if not its an
        // invalid file
            if (qPeek.startsWith(">")) {

            }

        }
...