Data Structures and Algorithms

Algorithm Find the level of the node whose node value is x in a binary tree

Find the level of the node whose node value is x, considering the unique case of the node int find_node_level(BTNode *bt, ElemType x, int h) { if (bt == NULL) return 0; else if (bt->data == x) return h; else { int l = find_node_level(bt->lchild, x, h+1); if (l != 0) return l; else return …

Algorithm Find the level of the node whose node value is x in a binary tree Read More »

[Sword Pointing OFFER] Tree JZ36 Binary Search Tree and Doubly Linked List

Article directory @[TOC] 1. Topic 2. Solution 2.1 The structure of the tree 2.2 Solution 1 Summarize 1. Topic Input a [binary search tree] , convert the binary search tree into a sorted doubly linked list. 2. Solution 2.1 The structure of the tree class TreeNode { int val = 0; TreeNode left = null; …

[Sword Pointing OFFER] Tree JZ36 Binary Search Tree and Doubly Linked List Read More »

Sequential lookup and sequential lookup of java versions with sentinels

import java.util.Arrays; import java.util.Random; class seqSearch { public static void main(String[] args) { seqSearch sq= new seqSearch(); //Generate a random array Random r = new Random(); int arr[] = new int [ 10 ]; for ( int i= 0 ;i<arr.length;i++){ arr[i] =r.nextInt(10); } System.out.println(Arrays.toString(arr)); System.out.println(sq.SeqSearch(arr,arr.length,3)); System.out.println(sq.SeqSearch2(arr,arr.length,3)); } /* Sequential search is also known as linear …

Sequential lookup and sequential lookup of java versions with sentinels Read More »

LeetCode training (2) sum of two numbers, merge two ordered arrays

For LeetCode Day -02 topic source: https://leetcode-cn.com/ sum of two numbers Simple Given an integer [array] nums and an integer target value target, please find the two integers in the array whose sum is the target value target, and return their array indices. You can assume that there will only be one answer for each …

LeetCode training (2) sum of two numbers, merge two ordered arrays Read More »

java data structure—PriorityQueue (priority queue, heap)

java [data structure] —PriorityQueue (priority queue, heap) 1. What is PriorityQueue (priority queue, heap) 2. How to use 1. What is PriorityQueue ( [priority queue] , heap) The nature of the normal [queue] is first in, first out, elements are added at the end of the queue and popped at the head of the queue. …

java data structure—PriorityQueue (priority queue, heap) Read More »

Data Structures and Algorithms – Linear Search – Sequential Search

This article is an original article by joshua317, please indicate: reprinted from joshua317 blog  Data Structure and Algorithm – Linear Search – Sequential Search – joshua317’s blog A brief description of [sequential search] What is a sequential search? Sequential search is to traverse the entire data list, and compare the elements with the given value …

Data Structures and Algorithms – Linear Search – Sequential Search Read More »