Pushd commands and stack principles in linux today I read the pushd commands in linux: I feel good. We can push the directory pushd to the directory stack, and then switch the directory through pushd. However, this command has an additional function + n and-n. It will move the elements in the stack. In fact, pushd is not...
Pushd commands and stack principles in linux today I read the pushd commands in linux: I feel good. We can push the directory pushd to the directory stack, and then switch the directory through pushd. However, this command has an additional function + n and-n. The elements in the stack will be moved. In fact, without adding a parameter to pushd, the elements in the stack will be moved. How can this be moved? I think the introduction on the Internet is not very clear. I opened the data structure and looked at it. A stack is a linear table that allows you to insert or delete elements at one end of a table. this end is called the top of the stack and the other end is called the bottom of the stack.
The basic operations of the stack are as follows: (1) InitStack (S) constructs an empty stack S. (2) StackEmpty (S) determines that the stack is empty. If S is empty, TRUE is returned; otherwise, FALSE is returned. (3) stack full (S. If S is full, TRUE is returned; otherwise, FALSE is returned.
Note: this operation is only applicable to the stack's sequential storage structure. (4) Push (S, x) to stack. If Stack S is not satisfied, element x is inserted to the top of stack S. (5) Pop (S) stack rollback. If Stack S is not empty, delete the top element of stack S and return this element. (6) StackTop (S) gets the top element of the stack. If Stack S is not empty, the top element of the stack is returned, but the stack status is not changed.
We don't need to consider the basic stack operation commands: 1, Operation 1, 2, and 3. these three commands have been processed before the call and are transparent to our users. 2, Operation 4, Stack Entry: pushd directory is this operation 3, Operation 5, stack rollback: popd is this operation 4, Operation 6, take the top element of the stack, it seems that there is no such operation, however, you can use dirs to view all elements in the stack. Enhanced stack functions: 1. for pushd without parameters, the first element on the top of the stack is switched to the second element. Tip: the current directory displays the first element in the current stack for all operations of this operation. 2. I mainly explain push + n and-n. The command www.2cto.com contains the shadow of the queue. When the elements in the stack move, they are all removed from the top of the stack and then inserted to the bottom of the stack. (1) We numbered the stack as an array, starting from the top of the stack... pushd + n does not move the number n to the top of the stack. the removed 0 to n-1 elements are inserted at the bottom of the stack in sequence. For example, after the elements in the stack are a, B, c, dpushd + 1, the elements are B, c, d, apushd + 2, and the elements are c, d,, elements remain unchanged after bpushd + 0: a, B, c, d
(2) the pushd-n command is the same as the above command, but the number is different. The number starts from the bottom of the stack (if there are four elements):-3,-2,-1,-0 pushd-n, move the number "-n" to the top of the stack, the removed elements from the top of the stack to-n + 1 are inserted to the bottom of the stack in sequence. For example, after the elements in the stack are a, B, c, dpushd-1, the elements are c, d, a, bpushd-2, and the elements are B, c, d, elements remain unchanged after apushd-0: d, a, B, c (3) Summary: Suppose there are n elements, then pushd-I and pushd + (n-1-i) is the same. For example, if there are four elements, pushd-2 is the same as pushd + (4-1-2. This makes it clear how the command moves the elements in the stack. Author: kongweile
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service