Lab 1 - (DS) - Skeleton Code For Singly Linked List - UA
Lab 1 - (DS) - Skeleton Code For Singly Linked List - UA
package linked.list;
import java.util.Scanner;
/**
*
* @author Usman
*/
class Node
{
protected int data;
protected Node link;
/* Constructor */
public Node()
{
}
/* Constructor */
public Node(int d,Node n)
{
}
/* Function to set link to next Node */
public void setLink(Node n)
{
}
/* Function to set data to current Node */
public void setData(int d)
{
}
/* Function to get link to next node */
public Node getLink()
{
}
/* Function to get data from current Node */
public int getData()
{
}
}
/* Class linkedList */
class linkedList
{
protected Node start;
public int size ;
/* Constructor */
public linkedList()
{
}
/* Function to check if list is empty */
public boolean isEmpty()
{
}
/* Function to get size of list */
public int getSize()
{
}
/* Function to insert an element at begining */
public void insertAtStart(int val)
{
}
/* Function to insert an element at end */
public void insertAtEnd(int val)
{
}
/* Function to insert an element at position */
public void insertAtPos(int val , int pos)
{
}
/* Function to delete an element at position */
public void deleteAtPos(int pos)
{
}
/* Function to display elements */
public void display()
{
}
}
int p = scan.nextInt() ;
if (p < 1 || p > list.getSize() )
System.out.println("Invalid position\n");
else
list.deleteAtPos(p);
break;
case 5 :
System.out.println("Empty status = "+ list.isEmpty());
break;
case 6 :
System.out.println("Size = "+ list.getSize() +" \n");
break;
default :
System.out.println("Wrong Entry \n ");
break;
}
/* Display List */
list.display();
System.out.println("\nDo you want to continue (Type y or n) \n");
ch = scan.next().charAt(0);
} while (ch == 'Y'|| ch == 'y');
}
}