NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*

/**
*
* @author 3csc-01
*/
public class SLL<T> {

public SLLNode<T> head,tail;

public SLL() //contructor gagawing null ang head at tail sa umpisa
{
head=tail=null;
}

public boolean isEmpty()
{
return head==null; //walang laman yung head, walang nirerefer
}

public void addToHead(T el) {
head = new SLLNode<T>(el,head);
if (tail == null)
tail = head; // only node of
}

public void addToTail(T el) {
if (isEmpty())
head = tail = new SLLNode<T>(el);
else {
tail.next = new SLLNode<T>(el);
tail = tail.next;
}
}

public T deleteFromHead() {
if (isEmpty())
return null; //nothing to delete
T el = head.info;
if (head == tail) // only one node
head = tail = null; // now empty list
else
head = head.next; // next node is head
return el;
}

public T deleteFromTail() {
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 = null; }
return el;
}
public String toString() { // you can use this for toString()
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; // a node if found, null if not
}
public boolean isInList(T el) {
return getNode(el) != null; // true if found, false if not
}

public void insertAfterNode(T el, SLLNode<T> ptr ) {
if (ptr != null)
if (tail == ptr) addToTail(el);
else ptr.next = new SLLNode<T>(el, ptr.next);
}
public void insertAfterElt(T elOld, T elNew) {
SLLNode<T> p;
p = getNode(elOld); // find node with el
if (p != null) insertAfterNode(elNew, p); // found, insert after
}

public T delete(T el) { // delete node with element el
if (isEmpty()) return null;
if (el == head.info) return deleteFromHead();
if (el == tail.info) return deleteFromTail();
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 insertSorted(T t){

SLLNode p;

if(isEmpty())
{
addToHead(t);
}

else if(((Integer)(t)).compareTo((Integer)head.info)<=0)
addToHead(t);

else{
for(p=head; p.next!=null&&((Integer)(t)).compareTo((Integer)p.next.info)>0;p=p.next);

if(p==null)
addToTail(t);
else
insertAfterNode(t,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.