Đang chuẩn bị liên kết để tải về tài liệu:
Data Structures and Algorithms in Java 4th phần 4

Không đóng trình duyệt đến khi xuất hiện nút TẢI XUỐNG

Ví dụ, định nghĩa cấu trúc của bức tường là như nhau từ nhà này sang nhà khác, thường đượcphương pháp ADT danh sách mảng trên một đại diện. Là nó tốt hơn để lưu trữ các mục trong L chỉ số tăng hay không? C-6,17, đơn giản, nhưng không hiệu quả thuật toán, được gọi là bong bóng sắp xếp, phân loại S trình tự của n yếu tố so sánh. | and then fill the array back up again by popping the elements off of the stack. In Code Fragment 5.8 we give a Java implementation of this algorithm. Incidentally this method also illustrates how we can use generic types in a simple application that uses a generic stack. In particular when the elements are popped off the stack in this example they are automatically returned as elements of the E type hence they can be immediately returned to the input array. We show an example use of this method in Code Fragment 5.9. Code Fragment 5.8 A generic method that reverses the elements in an array of type E objects using a stack declared using the stack E interface. A non recurs vê generic method for reversing an array public static E void reverse E a Stack E s new ArrayStack E a.length for inf i-.O i a.length i j S.pushfaji for int i 0 i 3.length i a i s.pop J Code Fragment 5.9 A test of the reverse method using two arrays. 278 . Tester routine for reversing arrays public static void main String args Integer a 4. 8. 15. 16 23r 42 autoboxing allows this String s Jack11 Kate Hurley Jin Boone System .out. printing a - Arrays.toString a System .out printing ns Arrays.toStfing s System.out.printlnl Reversing . J reverse a reverses System.out.prjndni a Arrays.toString a System.out.println s - Arrays.toStri ig si The output from this method is the following a 4 8 15 16 23 42 s Jack Kate Hurley Jin Michael Reversing. a 42 23 16 15 8 4 s Michael Jin Hurley Kate Jack 5.1.5 Matching Parentheses and HTML Tags In this subsection we explore two related applications of stacks the first of which is for matching parentheses and grouping symbols in arithmetic expressions. Arithmetic expressions can contain various pairs of grouping symbols such as Parentheses and Braces and Brackets and Floor function symbols and Ceiling function symbols and and each opening symbol must match with its corresponding closing symbol. For example a left bracket must match with a corresponding right bracket as .

Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.