Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // LL
- public void print() {
- Node<T> tmp = head;
- while (tmp != null) {
- sop(tmp.data);
- tmp = tmp.next;
- }
- }
- // AL
- public void print() {
- for (int i = 0; i < size; i++) {
- sop(nodes[i]);
- }
- }
- //LL
- public void removeEquals(T x) {
- Node<T> tmp = head;
- while (tmp != null) {
- if (tmp.data.equals(x)) {
- Node<T> prev = head;
- while (prev.next != tmp) {
- prev = prev.next;
- }
- prev.next = tmp.next;
- }
- tmp = tmp.next;
- }
- }
- //LL
- public void removeEquals2(T x) {
- Node<T> tmp = head;
- Node<T> prev = null;
- while (tmp != null) {
- if (tmp.data.equals(x)) {
- prev.next = tmp.next;
- }
- prev = tmp;
- tmp = tmp.next;
- }
- }
- // LL
- public T MFE() {
- int mfc = 0;
- T mfe = null;
- Node<T> tmp1 = head;
- while (tmp1 != null) {
- int c = 1;
- Node<T> tmp2 = tmp1.next;
- while (tmp2 != null) {
- if (tmp1.data.equals(tmp2.data)) {
- c++;
- }
- tmp2 = tmp2.next;
- }
- if (c > mfc) {
- mfe = tmp1.data;
- mfc = c;
- }
- tmp1 = tmp1.next;
- }
- return mfe;
- }
- // LL
- public void removeDuplicate() {
- Node<T> tmp1 = head;
- while (tmp1 != null) {
- Node<T> tmp2 = tmp1.next;
- Node<T> prev = tmp1;
- while (tmp2 != null) {
- if (tmp1.data.equals(tmp2.data)) {
- prev.next = tmp2.next;
- }
- prev = tmp2
- tmp2 = tmp2.next;
- }
- tmp1 = tmp1.next;
- }
- }
- // LL
- public void reverse() {
- Node<T> tmp = head;
- Node<T> newHead = null;
- while (tmp != null) {
- Node<T> next = tmp.next;
- tmp.next = newHead;
- newHead = tmp;
- tmp = next;
- }
- head = newHead;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement