Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA Part 1 - Building Blocks These are the items you should complete in Part 1:

ID: 3805153 • Letter: J

Question

JAVA

Part 1 - Building Blocks

These are the items you should complete in Part 1:

Create Word, Page, MyQueue and Node classes as described by the Javadoc

Pass all provided JUnit test cases for Word, Page and MyQueue

Overview

This project is going to require a number of components to put together the entire crawling & search experience. In parts 1 & 2, In this section, we will create ways to represent Pages and Words in our project, as well as create a way for us to Queue items for processing.

Representing Words and Pages

One idea is to think of words and pages as objects. Let's start by looking at what a page is. A page to us is just a web page that has a URL and an ID number that we give it when we first see it.

Page.java

Briefly look ahead to how we're going to store all of the information and relationships between Pages and Words by going to the Building an Index section in Part 3. As you can see, each word needs to hold a list of associated web pages. If we think of Words as objects, we can have our Word object contain a List that contains these IDs for us.

Word.java

Queuing Items

As each website is visited and successfully parsed, the list of websites to visit grows with each new (i.e. unvisited) web page. To accomplish this, you are going to implement a Queue. The MyQueue and Node classes that you will need to implement are described in the next section.

As described above, we need some type of data structure that will allow us to add items to the end and quickly grab the first item as necessary, with no traversing. For this, we are going to use a Queue:

For this we will have 2 classes - MyQueue and Node.

Your MyQueue class will house all of the operations you have seen with other classes like ArrayList, such as add() and remove(). Your Queue will be composed of linked together Node objects, and the methods defined below will be responsible for managing these linkages.

MyQueue.java

The Node class is the basic component to the your Queue. Each Node represents an entry, and you will add, remove, and update references (next & previous) as necessary.

Node.java

The data type for each Node is listed as Object because you will choose what you want to store (e.g. you could store Strings, Pages, etc). You can think of a Queue as a number of linked Node objects, where each Node's next reference links to the next Node in the chain.

If the next reference is null, we have reached the end of the Queue. Below is an illustration of a Queue with 3 nodes. The data component is storing an Integer. Also note how the first element is labeled “Head” and the last item has its' next reference set to null. We will keep the former as a global Node reference while the latter will help us identify the end of the Queue.

Explanation / Answer

Answer:

#include<iostream>
using namespace std;
struct node
{
    int info;
    node *later;
}*front_end = NULL,*rear_end = NULL,*p = NULL,*node_pointer = NULL;
void push(int value)
{
    node_pointer = new node;
    node_pointer->info = value;
    node_pointer->later = NULL;
    if(front_end == NULL)
    {
        front_end = rear_end = node_pointer;
        rear_end->later = NULL;
    }
    else
    {
        rear_end->later = node_pointer;
        rear_end = node_pointer;
        rear_end->later = NULL;
    }
}
int remove()
{
    int value;
    if(front_end == NULL)
    {
        cout<<" queue is empty ";
    }
    else
    {
        p = front_end;
        value = p->info;
        front_end = front_end->later;
        delete(p);
        return(value);
    }
}
int main()
{
    int n,c = 0,value;
    cout<<"Enter the number of values to be pushed into queue ";
    cin>>n;
    while (c < n)
    {
   cout<<"Enter the value to be entered into queue ";
   cin>>value;
        push(value);
        c++;
     }
     cout<<" Deleted Values ";
     while(true)
     {
        if (front_end != NULL)
            cout<<remove()<<endl;
        else
            break;
     }
   
}