Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

So I am working on an assignment where we make a rudimentary browser history with c#. The requirement is that we need to use a

So I am working on an assignment where we make a rudimentary browser history with c#. The requirement is that we need to use a linked list to do this. The issue that I am having is that when I want to go backwards in the history and print it takes from the beginning of the list and not the front. (Example is if I had a list with 1, 2, 3, 4 in it and went back It would be 2, 3, 4 and 1 gets moved to the future category).

Here is what I currently have:

public class UnderflowException : Exception

{ public UnderflowException(string s) : base(s) { } }

public class OverflowException : Exception

{ public OverflowException(string s) : base(s) { } }

class History

{

protected class IntListNode

{

public string Data;

public IntListNode Next;

public IntListNode(string data)

{

Data = data;

}

public IntListNode(string data, IntListNode next)

{

Next = next;

}

}

protected IntListNode first;

private int i;

public void PrintAll()

{

int j = 0;

IntListNode node = first;

Console.WriteLine("Privious things that you have viewed.");

while (node != null)

{

if (counter <= j)

{

break;

}

Console.WriteLine(node.Data);

node = node.Next;

j++;

}

Console.WriteLine("Things to go forward to.");

while (node != null)

{

Console.WriteLine(node.Data);

node = node.Next;

j++;

}

}

private int counter;

public void MoveBackwards()

{

if(counter >= 0)

{

counter = counter -1;

}

else

{

throw new UnderflowException("underflow");

}

}

public void MoveForwards()

{

if (counter > i)

{

throw new OverflowException("overflow");

}

else

{

counter++;

}

counter++;

}

public void VisitPage(string desc)

{

IntListNode n = new IntListNode(desc);

n.Next = this.first;

this.first = n;

counter++;

i = counter;

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions