|
938 | 938 | }, |
939 | 939 | "DequeLL": { |
940 | 940 | "addFirst": { |
941 | | - "code": [], |
942 | | - "english": [] |
| 941 | + "code": [ |
| 942 | + ["procedure addFirst(data)"], |
| 943 | + [" if size == 0"], |
| 944 | + [" head ← new Node(data)"], |
| 945 | + [" tail ← head"], |
| 946 | + [" else"], |
| 947 | + [" Node newHead ← new Node(data)"], |
| 948 | + [" newHead.next ← head"], |
| 949 | + [" head.prev ← newHead"], |
| 950 | + [" head ← newHead"], |
| 951 | + [" size++"], |
| 952 | + ["end procedure"] |
| 953 | + ], |
| 954 | + "english": [ |
| 955 | + ["procedure addFirst(data)"], |
| 956 | + [" if (list is empty):"], |
| 957 | + [" head points to new node"], |
| 958 | + [" tail points to new node"], |
| 959 | + [" else:"], |
| 960 | + [" create newHead node with data"], |
| 961 | + [" newHead.next points to head"], |
| 962 | + [" head.prev points to newHead"], |
| 963 | + [" head points to newHead"], |
| 964 | + [" increment size"], |
| 965 | + ["end procedure"] |
| 966 | + ] |
943 | 967 | }, |
944 | 968 | "addLast": { |
945 | | - "code": [], |
946 | | - "english": [] |
| 969 | + "code": [ |
| 970 | + ["procedure addLast(data)"], |
| 971 | + [" if size == 0"], |
| 972 | + [" tail ← new Node(data)"], |
| 973 | + [" head ← tail"], |
| 974 | + [" else"], |
| 975 | + [" Node newTail ← new Node(data)"], |
| 976 | + [" newTail.prev ← tail"], |
| 977 | + [" tail.next ← newTail"], |
| 978 | + [" tail ← newTail"], |
| 979 | + [" size++"], |
| 980 | + ["end procedure"] |
| 981 | + ], |
| 982 | + "english": [ |
| 983 | + ["procedure addLast(data)"], |
| 984 | + [" if (list is empty):"], |
| 985 | + [" head points to new node"], |
| 986 | + [" tail points to new node"], |
| 987 | + [" else:"], |
| 988 | + [" create newTail node with data"], |
| 989 | + [" newTail.prev points to tail"], |
| 990 | + [" tail.next points to newTail"], |
| 991 | + [" tail points to newTail"], |
| 992 | + [" increment size"], |
| 993 | + ["end procedure"] |
| 994 | + ] |
947 | 995 | }, |
948 | 996 | "removeFirst": { |
949 | | - "code": [], |
950 | | - "english": [] |
| 997 | + "code": [ |
| 998 | + ["procedure removeFirst()"], |
| 999 | + [" T data ← head.data"], |
| 1000 | + [" head ← head.next"], |
| 1001 | + [" if head == null"], |
| 1002 | + [" tail ← null"], |
| 1003 | + [" else"], |
| 1004 | + [" head.prev ← null"], |
| 1005 | + [" size--"], |
| 1006 | + [" return data"], |
| 1007 | + ["end procedure"] |
| 1008 | + ], |
| 1009 | + "english": [ |
| 1010 | + ["procedure removeFirst()"], |
| 1011 | + [" copy data at head to temp"], |
| 1012 | + [" head moves to next node"], |
| 1013 | + [" if (head is null):"], |
| 1014 | + [" null out tail"], |
| 1015 | + [" else:"], |
| 1016 | + [" null out head.prev"], |
| 1017 | + [" decrement size"], |
| 1018 | + [" return temp"], |
| 1019 | + ["end procedure"] |
| 1020 | + ] |
951 | 1021 | }, |
952 | 1022 | "removeLast": { |
953 | | - "code": [], |
954 | | - "english": [] |
| 1023 | + "code": [ |
| 1024 | + ["procedure removeLast()"], |
| 1025 | + [" T data ← tail.data"], |
| 1026 | + [" tail ← tail.prev"], |
| 1027 | + [" if tail == null"], |
| 1028 | + [" head ← null"], |
| 1029 | + [" else"], |
| 1030 | + [" tail.next ← null"], |
| 1031 | + [" size--"], |
| 1032 | + [" return data"], |
| 1033 | + ["end procedure"] |
| 1034 | + ], |
| 1035 | + "english": [ |
| 1036 | + ["procedure removeBack()"], |
| 1037 | + [" copy data at tail to temp"], |
| 1038 | + [" tail moves to previous node"], |
| 1039 | + [" if (tail is null):"], |
| 1040 | + [" null out head"], |
| 1041 | + [" else:"], |
| 1042 | + [" null out tail.next"], |
| 1043 | + [" decrement size"], |
| 1044 | + [" return temp"], |
| 1045 | + ["end procedure"] |
| 1046 | + ] |
955 | 1047 | } |
956 | 1048 | }, |
| 1049 | + |
957 | 1050 | "BST": { |
958 | 1051 | "preorder": { |
959 | 1052 | "code": [ |
|
0 commit comments