NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

package csdappliccation;
import java.util.*;
public class EXF4_38
{
public static Scanner input = new Scanner(System.in);
public static char again,head,tail;
public static void main(String[] args)
{
SLL<Character> sl = new SLL<Character>();
char choice,word,refer;
int num;
for(;;)
{
System.out.printf("Main menunA. Add NodenB. TracenC. MakeNull nD. ExitnChoose: ");
choice= input.next().charAt(0);
if((choice=='A')||(choice=='a'))
{
do
{
System.out.printf("Enter Character to add: ");
word=input.next().charAt(0);
sl.AddTail(word);
System.out.print("Again? ");
again= input.next().charAt(0);
}while((again=='y')||(again=='Y'));
continue;
}
else if((choice=='b')||(choice=='B'))
{
sl.Trace();
System.out.printf("nBack to Main: ");
again= input.next().charAt(0);
if ((again=='y')||(again=='Y'))
{
continue;
}
else
{
break;
}
}
else if((choice=='c')||(choice=='C'))
{
System.out.print("Are you sure?");
again= input.next().charAt(0);
if ((again=='y')||(again=='Y'))
{
sl = new SLL<Character>();
}
System.out.print("Back to Main: ");
again= input.next().charAt(0);
if ((again=='y')||(again=='Y'))
{
continue;
}
else
{
break;
}
}
else if((choice=='d')||(choice=='D'))
{
System.out.print("GoodBye!!!");
break;
}
else
{
System.out.printf("nWrong Input!!!");
continue;
}
}
}
public static class SLLNode<T>
{
public T info;
public SLLNode<T> next;
public SLLNode()
{
next = null;
}
public SLLNode(T el)
{
info = el;
next = null;
}
public SLLNode(T el, SLLNode<T> ptr)
{
info = el;
next = ptr;
}
}
public static class SLL<T>
{
private SLLNode<T> head, tail;
public SLL()
{
head = tail = null;
}
public boolean isEmpty()
{
return head == null;
}
public void AddHead(T el) {
head = new SLLNode<T>(el,head);
if (tail == null)
tail = head; // only node of list
}
public void AddTail(T el)
{
if (isEmpty())
head = tail = new SLLNode<T>(el);
else
{
tail.next = new SLLNode<T>(el);
tail = tail.next;
tail.next = head;
}
}
public T RemoveHead()
{
if (isEmpty())
return null;
T el = head.info;
if (head == tail)
head = tail = null;
else
head = head.next;
tail.next=head;
return el;
}
public T RemoveTail()
{
if (isEmpty())
return null;
T el = tail.info;
if (head == tail) // only one node
head = tail = null;
else
{
SLLNode<T> p; // find predecessor of tail
for (p = head; p.next != tail; p = p.next);
tail = p; // predecessor of tail is the new tail
tail.next = head;

}
return el;
}
public String Print()
{
SLLNode<T> p; String s = "";
for (p = head; p != null; p = p.next)
s=s+p.info.toString() + " ";
return s;
}
public SLLNode<T> GetNode(T el)
{
SLLNode<T> p = head;
while (p != null && p.info != el) p = p.next;
return p;
}
public void InsertAfter(T el, SLLNode<T> ptr )
{
if (ptr != null)
if (tail == ptr) AddTail(el);
else ptr.next = new SLLNode<T>(el, ptr.next);
}
public void InsertBefore(T el, SLLNode<T> ptr )
{
if (ptr != null)
if (head == ptr) AddHead(el);
else
{
SLLNode<T> pred, t; // find el’s predecessor
for (pred = head, t = head.next;
t != null && t.info != ptr.info;
pred = pred.next, t = t.next) ;
InsertAfter(el,pred);
}
}
public T delete(T el)
{ // delete node with element el
if (isEmpty()) return null;
if (el == head.info) return RemoveHead();
if (el == tail.info) return RemoveTail();
SLLNode<T> pred, t; // find el’s predecessor
for (pred = head, t = head.next;
t != null && t.info != el;
pred = pred.next, t = t.next) ;
if (t == null) return null; // if el was not found
else {
pred.next = t.next;
return el; }
}
public void Trace()
{
SLLNode<T> p = head;
if(isEmpty())
{
System.out.printf("List is Emptyn");
}
else
{
do
{
System.out.print(delete(p.info)+" ");
p=p.next.next.next.next;
}while(p.next!=p);
}
}
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.