Add the module TypeScript code (Chapter of Linkedlist)
This commit is contained in:
		
							
								
								
									
										9
									
								
								codes/typescript/module/ListNode.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								codes/typescript/module/ListNode.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | |||||||
|  | // Definition for singly-linked list. | ||||||
|  | export default class ListNode { | ||||||
|  |     val: number; | ||||||
|  |     next: ListNode | null; | ||||||
|  |     constructor(val?: number, next?: ListNode | null) { | ||||||
|  |         this.val = val === undefined ? 0 : val; | ||||||
|  |         this.next = next === undefined ? null : next; | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										18
									
								
								codes/typescript/module/PrintUtil.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								codes/typescript/module/PrintUtil.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,18 @@ | |||||||
|  | /* | ||||||
|  |  * File: PrintUtil.ts | ||||||
|  |  * Created Time: 2022-12-10 | ||||||
|  |  * Author: Justin (xiefahit@gmail.com) | ||||||
|  |  */ | ||||||
|  |  | ||||||
|  | import ListNode from './ListNode'; | ||||||
|  |  | ||||||
|  | function printLinkedList(head: ListNode | null): void { | ||||||
|  |     const list: string[] = []; | ||||||
|  |     while (head !== null) { | ||||||
|  |         list.push(head.val.toString()); | ||||||
|  |         head = head.next; | ||||||
|  |     } | ||||||
|  |     console.log(list.join(' -> ')); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | export { printLinkedList }; | ||||||
		Reference in New Issue
	
	Block a user