Лекция №5. Линейные структуры данных. Предмет "Структуры и алгоритмы обработки данных"

  • Published on
    26-Jun-2015

  • View
    1.612

  • Download
    8

Embed Size (px)

Transcript

  • 1. . .. : , www.grebenshikov.ru

2. - - .{a, b, c, d, e} (a, b, c, d, e): .. 1 3. - - . X. - n x(n), n {1, . . . , N }, x(n) X. x(n) - n, N N - .2 4. 1interface List { 2 void insert(object o, Position position); 3 Position getPosition(object o); 4 object getAt(Position position); 5 void deleteAt(Position position); 6 Position next(Position position); 7 Position previous(Position position); 8 Position end(); 9 Position first(); 10void clear(); 11 }3 5. 4 6. 1 class ArrayList { 2private final int MAX_COUNT = 1000; 3private Object[] objects = new Object[MAX_COUNT]; 4private int last = 0; 5int end() { 6 return last + 1; 7} 8 }5 7. 1void insert(object o, int position) { 2 int q; 3 if (last >= MAX_COUNT) { error( ); } 4 else if (position > last || p < 0) { 5error( ); 6 }else { 7for (int i = last; i >= p; i--) { 8objects[i+1] = object[i]; 9} 10 last++; 11 objects[p] = o; 12} 13 }6 8. 7 9. 1class PointerListElement { 2 public object data = null; 3 public PointerListElement next = null; 4} 5class PointerList { 6 private PointerListElement head = 7new PointerListElement(); 8 PointerListElement end() { 9PointerListElement result = head; 10 while(result.next != null) { 11 result = result.next; 12 } 13 return result 14} 15 } 8 10. 1 void insert(object o, PointerListElement position) { 2PointerListElement newElement = 3 new PointerListElement(); 4newElement.data = o; 5newElement.next = position.next; 6position.next = newElement; 7 }9 11. : 10 12. : 11 13. 1 class PointerListElement { 2public object data = null; 3public PointerListElement next = null; 4public PointerListElement previous = null; 5 }12 14. 13 15. - , , .LIFO - last in rst out. 1interface Stack { 2 void push(object o); 3 object pop(); 4 object top(); 5 boolean isEmpty(); 6 void clear(); 7} 14 16. 15 17. 1class ArrayStack { 2 private final int MAX_COUNT = 1000; 3 private Object[] objects = new Object[MAX_COUNT]; 4 private int top = MAX_COUNT; 5 void push(object o) { 6if (top ? 22 24. ., ., . . - . : , 2000..45-76. ., ., ., . -: , 2- . - . : - , 2007. .260-268. , , 1. , 3- . - . : ,2000. .277-351. 23

Recommended

View more >