Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ListaRealnih {
- class Element {
- double info;
- Element point;
- public Element (double nu) {
- this.info = nu;
- this.point = null;
- }
- public String toString () {
- return info + (point != null ? " " + point : "");
- }
- }
- Element first, last;
- public ListaRealnih () {
- this.first = null;
- this.last = null;
- }
- public void addFront (double nu) {
- Element el = new Element(nu);
- el.point = first;
- first = el;
- if (last == null) {
- last = first;
- }
- }
- public void add (double nu) {
- Element el = new Element(nu);
- if (first == null) {
- addFront(nu);
- }
- else {
- last.point = el;
- last = el;
- }
- }
- public void deleteB (double nu) {
- boolean done = false;
- Element runThrough = first.point;
- Element rem = first;
- if (rem.info == nu) {
- first = first.point;
- done = true;
- }
- while (runThrough != null && !done) {
- if (runThrough.info == nu) {
- rem.point = runThrough.point;
- done = true;
- }
- else {
- runThrough = runThrough.point;
- rem = rem.point;
- }
- }
- }
- public void insertCtoB(double nu1, double nu2) {
- Element c = new Element (nu1);
- Element beforeB = new Element(0);
- Element afterB = first;
- boolean none = false;
- while (afterB.point != null) {
- if (afterB.point.info == nu2) {
- beforeB = afterB;
- afterB = afterB.point;
- none = true;
- } else {
- afterB = afterB.point;
- }
- }
- if (first.info == nu2 && !none) {
- c.point = first.point;
- first = c;
- } else {
- c.point = beforeB.point.point;
- beforeB.point = c;
- }
- }
- public void deleteMin() {
- Element beforeMin = first;
- Element runThrough = first;
- while (runThrough.point != null) {
- if (runThrough.point.info < beforeMin.point.info) {
- beforeMin = runThrough;
- runThrough = runThrough.point;
- } else {
- runThrough = runThrough.point;
- }
- }
- if (first.info < beforeMin.info) {
- first = first.point;
- } else {
- beforeMin.point = beforeMin.point.point;
- }
- }
- public void firstToLast () {
- last.point = first;
- last = first;
- first = first.point;
- last.point = null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement