“JavaScript Advanced Programming” Reading Notes (3) – Scope, Recursion, Closure

Execution environment and scope Execution environment(execution context) defines other data that the variable or function has access to, determining their respective behavior. Each execution environment will correspond to a variable object (variable object). All variables and functions defined in the environment are stored in this object, which is a variable object. properties or methods. This object cannot be accessed by writing code and is used by the parser when processing data in the background. Global execution environment is the most peripheral execution environment, which is considered as window object in web browsers. After all code in an execution environment has been executed, the environment is destroyed, and all variable and function definitions saved in it are also destroyed. The global execution environment is destroyed until the application exits (closes the web page/browser). Each function has its own execution environment (it can be understood that the function itself is an execution environment). Execution flow mechanism – When a function is executed, the environment of the function will be pushed into an Environment stack. After the function is executed, the stack will Pop up and return control to the previous execution environment. When code is executed in an execution environment, a scope…

Insert image description here

The fourth day of Java dry knowledge learning memory division, recursion, first understanding of arrays

1 Memory division 1.1 Related knowledge Program:Executable file(Instruction set),It is Static concepts are generally saved on the hard disk. Process:The file being executed, is a dynamic concept;When the program is running,it refers to the program that can be loaded into the memory. Executing the file – the operating system will start a process to run this object in the memory – if you want to close the process – you can kill the process directly. 1.2JVM memory division The class file is a static concept ,saved on the hard disk. When the JVM command is executed, the class file will be loaded. Memory. Java Runtime Data Area:Java runtime data area,We generally call it JVM memory. 1.21 Five areas of memory The memory is divided into five areas:program counter,method area/static area/static code segment,stack Memory (Virtual Machine Memory),Local Method Stack,Heap Memory. Program Counter:A small memory area,The function can be regarded as the currently executed line number,For example if&#xff0c ;Loop ,Jump,Exception handling, etc. need to use it. Method area: Used to save class files loaded into memory,including methods,and code segments,There is an internal Run constant pool. Stack memory:Stack(Data structure,First in last out);Methods are executed in stack memory& #xff0c; Local variables are also in…

3.1_10JavaSE Getting Started P9 [Common API] Scanner, Object, String, StringBuilder, Recursion

java api object string build excel Programming Array char Write your review! Come on, watch it all Member login | User registration Recommended reading (adsbygoogle = window.adsbygoogle || []).push({}); <!– –> .syntaxhighlighter{ width: 740px; padding-top:40px;padding-bottom:20px; border: 1px solid #333; background: url(“/style/SyntaxHighlighter/top_bg.svg”); background-size: 43px; background-repeat: no-repeat; margin-bottom: -7px; border-radius: 15px; background-position: 16px 12px; padding-left: 10px; } .gutter{ display: none; }

[Data structure] Traversal of binary tree (dynamic diagram, c++, java, recursion, multi-thread non-recursion)

java git struct go view Search Algorithm Pictures tree Write your review! Come on, watch it all Member login | User registration Recommended reading (adsbygoogle = window.adsbygoogle || []).push({}); <!– –> .syntaxhighlighter{ width: 740px; padding-top:40px;padding-bottom:20px; border: 1px solid #333; background: url(“/style/SyntaxHighlighter/top_bg.svg”); background-size: 43px; background-repeat: no-repeat; margin-bottom: -7px; border-radius: 15px; background-position: 16px 12px; padding-left: 10px; } .gutter{ display: none; }

34efbc1c5b3e4a5468800995117ab312.png

Java determines the return value of the previous method_java basics 5 (method, return value, overloading, recursion)

Method: Define a way to solve a problem. A block of code with a specific function Features: 1. Methods will not be executed if they are not called 2. Methods cannot be nested outside of methods in a class Methods with return value types Definition format: Modifier return value type method name ([parameter list]) { Method body statement; return return value; } ①Modifier: access permission modifier public static ②Return value type: After the method is executed, the data type of the result Basic data type | Reference data type ③Method name: The identifier matches the identifier Naming rules and specifications, method calls should be based on the method name ④()–>Parameter list: parameters can be present, absent, or multiple parameters In the method definition When, unknown and uncertain values ​​are defined in the parameter list Data type parameter name 1, data type parameter 2,… Parameters are equivalent to the declaration of local variables ⑤{}->Code blocks with specific functions ⑥return: 1) End the method early 2) Bring out the return value Method call: Method name (parameter); –>Execution method Code in Call of method with return value type: 1. Directly call the method name (parameter); 2. Assignment call data type variable name =…

java linear table monkey chooses the king, linear table application: Joseph problem (monkey chooses the king) (circular linked list, array, recursion)…

1 Description: A group of monkeys want to choose a new monkey king. The selection method for the new monkey king is to “let N candidate monkeys form a circle” and number them sequentially from 1 to N starting from a certain position. Counting starts from No. 1 and counts from 1 to 3 in each round. Any monkey that reports 3 will exit the circle and then starts the same counting from the next monkey. 2 This cycle continues,The last remaining monkey is selected as the monkey king. May I ask which monkey was originally elected as the Monkey King? 3 //Use a circular linked list 4 #include 5 #include 6 7 typedef struct node 8 { 9 int data; 10 struct node *next; 11 }node; 12 13 node *create(int n) 14 { 15 node *head; 16 node *p = NULL; 17 head = (node ​​*)malloc(sizeof(node)); 18 p = head; //p is the pointer to the current node 19 node *s; 20 int i = 1; 21 22 if(n != 0) 23 { 24 while(i <= n) 25 { 26 s = (node ​​*)malloc(sizeof(node)); //Temporary node 27 s->data = i++; //The value of the first node is 1 and…

206. Reverse linked list (Java, double pointer method, recursion)

Give you the head node of a singly linked list head ,Please reverse the linked list, and return the reversed linked list. Input :head = [1,2,3,4,5]Output :[5,4,3, 2,1]Input:head = [1,2]Output:[2,1] LeetCode – Question address Code Thoughts – Detailed Explanation of the Question Idea The idea of ​​this question is very simple , you only need to change the direction of the pointer of the linked list. Code Double pointer method /*** Definition for singly-linked list.* public class ListNode {* int val;* ListNode next;* ListNode() {}* ListNode(int val) { this.val = val; }* ListNode(int val, ListNode next) { this. val = val; this.next = next; }* }*/class Solution {public ListNode reverseList(ListNode head) {// Double pointer methodListNode temp = null ;ListNode cur = head; ListNode pre = null span>;while (cur != null) {temp = cur.next;cur.next = pre;pre = cur;cur = temp;}return pre;}} Recursion /*** Definition for singly-linked list.* public class ListNode {* int val;* ListNode next;* ListNode() {}* ListNode(int val) { this.val = val; }* ListNode(int val, ListNode next) { this.val = val; this .next = next; }* }*/class Solution {public ListNode reverse(ListNode pre, ListNode cur) {if (cur == null) return pre ;ListNode temp = null;temp = cur. next;// Reversecur.next = pre;//…

JavaScript advanced – function advancement (including: function definition and calling, this pointer and changing this pointer (call(), apply(), bind())), strict mode, higher-order functions, closures, recursion, Shallow copy and deep copy)

Definition and calling of functions 1. How to define functions (1) How to declare functions function keyword (named function) function fn(){ }; (2) Function expression (anonymous function) var fun = function(){ }; (3&#

[LeetCode Notes] 538. Convert binary search tree to cumulative tree (Java, binary search tree, recursion)

Article directory Problem description Ideas & code Updated version Problem description Note that it is a binary search tree ,You can find out the order! Somewhat similar to In-order traversal Idea & Code Idea:The current node root takes the parent value and goes all the way to the right ,Accumulate the right values ​​one by one Update root.val += rightSum, Then use root.val as the parent value of the left subtree,Recursively This process The left subtree recursively ends,The stack frame of the current root returns the value of the left subtree(After all, this is the maximum value) Time complexity O(n), is equivalent to traversing each node /*** Definition for a binary tree node.* public class TreeNode {* int val;* TreeNode left;* TreeNode right;* TreeNode() {}* TreeNode(int val) { this.val = val ; }* TreeNode(int val, TreeNode left, TreeNode right) {* this.val = val;* this.left = left;* this.right = right;* }* }* /class Solution {public TreeNode convertBST(TreeNode root) {toConvertBST(root, 0);return root;}// Returned to the parent node Assignment(The leftmost value of the currently updated subtree)int toConvertBST(TreeNode root, int paNum){// Go to the right Go all the way to the end and return the parent valueif(root == null){return paNum;}// First pass the parent…

PHP two ways to achieve Fibonacci numbers [recursion, recursion]

Fibonacci number , also known as Fibonacci sequence ( Italian : Successione di Fibonacci) , Naxi number sequence, Fibonacci number, Fibonacci number sequence , refers to such a sequence : 1, 1, 2, 3, 5, 8, 13, 21, … in mathematics&#xff1a xff0c;The Fibonacci sequence is defined recursively as follows :F0=0,F1=1,Fn=Fn-1+Fn-2(n>=2,n∈N*)& #xff0c; In words, , is the Fibonacci sequence starting from 0 and 1. The coefficient of the Fibonacci sequence after that is the addition of the previous two numbers. 1 Use the recursive method. Think along the lines of thought , f(1)= 1; f(2) = 1 ; f(3) = f(2)+f(1) 【 2】 f(4) = f(3)+f(2) 3 //Use recursion to find Fibonacci numbers public function fb($n){ //if( $n <=2){return 1;}else{return fb($n -1) + fb($n-2);}} 2 Use the recursion method. public function fb2($n){ //if( $n < =2){return 1;}$t1 = 1;$t2 = 1;for($i=3;$i<$n;$i+&#43 ;){$temp = $t1;$t1 = $t2;$t2 = $temp + $t2;}return $t1 + $t2;} Finally,Performance analysis. Obviously predictable ,recursive method,each additional level,recurses down twice. It is about O(2 to the Nth power) and the recursive algorithm is O(n). The measured code is as follows. /**Performance test. */function bench_profile($starttime , $flag = ''){$endtime = explode(' ',microtime());$ thistime = $endtime[0]+$endtime[1]-($starttime[0]+$starttime[1]); $thistime = round($thistime,3) ;return…

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索