1 #initializing the nodes of a linked list2 classNode ():3 def __init__(Self,item):4Self.item =Item5Self.next =None6 7 #Incoming header node, gets the length of the entire list8 defLength (headnode):9 ifHeadnode = =None:Ten returnNone OneCount =0 ACurrentNode =Headnode - #tried a linked list with a ring, calculated whether the length would die in cycles, indeed, and added the count limit = =| | - whileCurrentNode! = None andCount : theCount+=1 -CurrentNode =Currentnode.n
The number of decimal places in a repeating prime number must be smaller than that in the prime number itself.
Generally, decimal places with the reciprocal of prime numbers are complex. Because the reciprocal of prime numbers is also a fraction, it must be a round-robin decimal (except for 2 and 5 ), but what is the maximum number of decimal places in the cycle of prime numbers? Is it possible to be v
*begin =head;slistnode*cur=head;while (Begin->_next) { while (Cur->_next) {if (cur->_data> cur->_next->_data) { swap (cur->_data,cur->_next->_data); }cur=cur->_next; }begin= begin->_next;}}5. find the middle node of a single linked list, which requires only one link list to be traversedSlistnode*findmiddle (Slistnode*head) {if (Head==NULL) {returnNULL; }SListNode*slow=head;SListNode* fast=head;while (Fast->_next) { if (Fast->_next) { fast=fast->_next; if (Fast->_next) { fast=fast->_next; }els
166 Chain List reciprocal nth node
Topic
http://www.lintcode.com/zh-cn/problem/nth-to-last-node-in-list/
Find the reciprocal nth node of a single linked list to ensure that the minimum number of nodes in the list is N.
ExampleGives the list 3->2->1->5->null and n = 2, and returns the value 1 of the penultimate node. train of Thought
-Reverse: From head to bottom n number, get the value code
' "'
Definitio
Number keys (1-9), 0 keys, positive and negative conversions, decimal point, square root take the reciprocal, CE, C, backspace, subtraction, equalsNumber keys (1-9):
Press the string on the screen to add a numeric character
If the first digit is pressed after the operator, the screen is first emptied and then
Judgment: There is no operator in front, if pressed, before the other number0 Keys:
Pressing the 0 key, as long as th
) ="+ a.tostring () +"\ n");//A (Ten) = 188Console.WriteLine ("A (+) ="+ a.tostring ("x") +"\ n");//A (+) = BCConsole.WriteLine ("A (+) ="+ a.tostring ("X") +"\ n");//A (+) = BC//at this time, we may have another requirement, that is, in order to show the results neatly, we need to control the length of the hexadecimal representation, if the length is not enough, with a leading 0 fill. //To solve this problem, we just need to write the number on the length after the format specifier "x" or "X".
requirement, that is, in order to show the results neatly, we need to control the length of the hexadecimal representation, if the length is not enough, with a leading 0 fill. To solve this problem, we just need to write the number on the length after the format specifier "x" or "X". For example, to limit the length of 4 characters, you can write "X4". In the example above, add a sentence:1. This.textBox1.AppendText ("a (+) =" + a.tostring ("X4") + "\ n");The result will be output a (+) = 00BC.
/// ///returns a encapsulated GDI + bitmap based on the Base64 string. /// /// a Base64 string that can be converted to a bitmap. /// The Bitmap object. PublicBitmap GetImageFromBase64 (stringbase64string) { byte[] B =convert.frombase64string (base64string); MemoryStream Ms=NewMemoryStream (b); Bitmap Bitmap=NewBitmap (MS); returnbitmap; } /// ///converts a picture into a base64 string. /// /// the picture file that needs to be c
example: Enum.getname (typeof (Colors), 3)) and Enum.getname (typeof (Colors), colors.blue) are all "Blue" valuesEnum.getnames (typeof (Colors)) returns an array of enumeration strings.String-->enum(1) The static method of using Enum, parse:public static Object Parse (Type enumtype,string value)For example: (Colors) Enum.parse (typeof (Colors), "Red")Enum-->int(1) Because the base type of the enumeration is an integral type other than Char, it is possible to cast.For example: (int) colors.red,
1. longitudinal table to Horizontal table:Longitudinal structure: Table1Converted cross-table structure:SQL Sample code:
1234567891011
selectusername,sum(caseCoursewhen‘语文‘thenGradeelse0end)as语文,sum(caseCoursewhen‘数学‘thenGradeelse0end)as数学,sum(caseCoursewhen‘英语‘thenGradeelse0end)as 英语fromTable1groupbyusername
2, the horizontal table to the longitudinal table :Horizontal Table structure: TableAID name Chinese Math english1 Sheets 380 90 702 Lee 490 85 953 Wang 588 75 90 t
The title description enters a linked list, outputting the penultimate K node in the list. Train of Thought: Method 1: Set 2 pointer p,q. P moves the K-time first, and then the PQ moves back, p to the end of the list, Q points to the last K-node. Attention://need to consider k=0, and the case of list is emptyMethod 2: Use the stack, first all stack, pop k times, get the countdown k node AC code:1 /*2 struct ListNode {3 int val;4 struct ListNode *next;5 listnode (int x):6 val (x), Next (NULL)
), method use consistent.Two or 10 binary conversion to other binary:String Integer. tobinarystring (int i);Returns the string form of an integer parameter as a binary unsigned integer.Integer.tobinarystring (10);//return: 1010String Integer. tooctalstring (int i);Returns the string form of an integer parameter as an octal unsigned integer.Integer.tooctalstring (10);//return: 12String Integer. tohexstring (int i);Returns a string form of an integer argument as an unsigned 16-based integer.Intege
Output the k-th node and the reciprocal node of a single-chain table.
Question: Enter the single-chain table L of the leading node, and output the k-last node of the single-chain table. The last 0th nodes of a Single-linked table are the tail pointers of the single-linked table. Only one single-chain table can be traversed.
Solution:If you do not need to traverse only one single-chain table at a time, we can traverse one single-chain table first a
method One: Use two pointers p,q, first move the Q to the tail of the chain N-bit, and then the P, Q back together, then when Q reached the end of the linked list, p that point to the penultimate node of the list.
Copy Code code as follows:
node* find_nth_to_last (node* head,int N) {if (Head==null | | n
method Two: The number of nodes can be calculated first, that is, to traverse the list from beginning to end, to get the number m, then the
using Java to realize the reciprocal mechanism between decimal and binary decimal
This blog mainly describes the use of Java to achieve decimal and binary decimal number of the mutual transfer (do not invoke Java-brought functions). Later may use the MATLAB realization, because our information security one experiment is the request Matlab realizes. Required
An experimental requirement of information security course1, write the program to achieve deci
This is the sword refers to the offer of a very classic problem, but also in the interview written in the high-frequency appearance. The detailed description of the topic is as follows: Enter a list and output the reciprocal K-nodes in the list. In order to conform to the habits of most people, counting starts at 1, that is, the tail node of the linked list is the last one.
There is a very intuitive solution, that is, scan the list two times, the firs
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.