Skip to content

Instantly share code, notes, and snippets.

public class LinkedListStackOfStrings{
private class Node{
private String item;
private Node next;
}
private Node first=null;
public boolean isEmpty(){
if(first==null)
return true;
else
public class LinkedListQueueOfStrings{
public class Node{
private String item;
private Node next;
}
private Node first=null;
private Node last=null;
public boolean isEmpty(){
return first==null;
}
public class ResizingArrayStackOfStrings{
private String[] s;
private int N;
public ResizingArrayStackOfStrings(){
s=new String[1];
N=0;
}
public boolean isEmpty(){
return N==0;
}
public class ResizingArrayQueueOfStrings{
private String[] s;
private int tail,head,size;
public ResizingArrayQueueOfStrings(){
tail=0;
head=0;
size=0;
s=new String[1];
}
public boolean isEmpty(){
import java.util.Iterator;
public class LinkedListStackOfStrings{
private class Node{
private String item;
private Node next;
}
public class ListIterator implements Iterator{
private Node current=first;
public boolean hasNext(){
return current!=null;
public class SelectionSort {
public static void sort(Comparable[] a){
int N=a.length;
for(int i=0;i<N;++i){
for(int j=i+1;j<N;++j){
if(less(a[i],a[j])){
exch(a,i,j);
}
}
}
public class BubbleSort {
public static void sort(Comparable[] a){
int N=a.length;
for(int i=N-1;i>0;--i){
for(int j=0;j<i;++j){
if(less(a[j],a[j+1]))exch(a,j,j+1);
}
}
}
public static boolean less(Comparable v,Comparable w){
public class InsertionSort {
public static void sort(Comparable[] a){
int N=a.length;
for(int i=1;i<N;++i){
for(int j=i;j>0;--j){
if(less(a[j-1],a[j]))exch(a,j,j-1);
else break;
}
}
}
public class Solution {
public boolean isMatch(String s, String p) {
if (s == null || p == null)
return false;
int len2 = s.length();
int len1 = p.length();
boolean[][] arr = new boolean[len1 + 1][len2 + 1];
arr[0][0] = true;
for (int i = 0; i < len1; i++) {
if (p.charAt(i) != '*')
public class Solution {
public boolean isMatch(String s, String p) {
return dfs(s, p, 0, 0);
}
private boolean dfs(String s, String p, int i, int j) {
//if we arrive at the end of p, but we have not arrived at the end of s,
//they will not match since it is impossible to match the rest part of s