1046: Linked List Exercise
Memory Limit:128 MB
Time Limit:2.000 S
Judge Style:Text Compare
Creator:
Submit:185
Solved:39
Description
A large array with consequtive memory space can hardly be allocated in a computer of low memory capacity, say 4 MB. Dynamical data structure such as "LINKED LIST" can be implemented to take of large amount of data stored distributedly in memory. In the following practice, one implements linked list that can store N elements, up to 1000000 and each storing integers ranging from -8 X 10^12 to 8 X 10^12 in a limited RAM (< 10 MB). The implemented linked list must support these operations:
1. < select the previous element (rewinding).
2. > select the next element (advancing).
3. = changes the current element to a value (updating).
4. + creates a new element with a value, shifting the current element back (inserting). The pointer will point at the
inserted element.
5. - removes the current element, shifts pointer to the next element (deleting).
6. ! prints the value of the current element (printing).
Note that your linked list starts empty, and it is possible to delete the last element in the list. In case the last element is deleted, the pointer will point at the last element. The pointers cannot go after the end of the list while proceeding the operators > (advancing), - (deleting).
The pointer cannot go before the beginning of list under the operation of < (rewinding).
Input Specification:
The first line will contain the integer , the number of operations to perform, up to 10'000'000.
The next lines will contain one of the operation labels, < , > , = , + , - , or ! . If the operation takes a value,
in case of = or + , then the label is followed by a space followed by an integer.
Output Specification:
For every ! operation, print the value at the linked list pointer.
1. < select the previous element (rewinding).
2. > select the next element (advancing).
3. = changes the current element to a value (updating).
4. + creates a new element with a value, shifting the current element back (inserting). The pointer will point at the
inserted element.
5. - removes the current element, shifts pointer to the next element (deleting).
6. ! prints the value of the current element (printing).
Note that your linked list starts empty, and it is possible to delete the last element in the list. In case the last element is deleted, the pointer will point at the last element. The pointers cannot go after the end of the list while proceeding the operators > (advancing), - (deleting).
The pointer cannot go before the beginning of list under the operation of < (rewinding).
Input Specification:
The first line will contain the integer , the number of operations to perform, up to 10'000'000.
The next lines will contain one of the operation labels, < , > , = , + , - , or ! . If the operation takes a value,
in case of = or + , then the label is followed by a space followed by an integer.
Output Specification:
For every ! operation, print the value at the linked list pointer.
Input
4
+ 100
+ 200
>
!
+ 100
+ 200
>
!
Output
100
Sample Input Copy
10
+ 100
+ 200
>
!
<
!
-
!
= 300
!
Sample Output Copy
100
200
100
300
HINT
Hint: use data type: long long