===

[size=medium]如果碰到===语法,突然一愣,那么需要巩固下它的定义。
但是,在百度谷歌搜索不到这个关键词。或许需要转义,但我不会。
以下是javascript中的定义:
---------------------------------------------------
比较运算符
返回表示比较结果的 Boolean 值。

expression1 comparisonoperator expression2

参数
expression1

任何表达式。

comparisonoperator

任何比较运算符。

expression2

任何表达式。

说明
比较字符串时,JScript 使用字符串表达式的 Unicode 字符值。

下面说明根据 expression1 和 expression2 的类型和值,不同组的运算符是如何作用的:

[b]关系运算符(<、>、<=、>=) [/b]
试图将 expression1 和 expression2 都转换为数字。
如果两表达式均为字符串,则按字典序进行字符串比较。
如果其中一个表达式为 NaN,返回 false。
负零等于正零。
负无穷小于包括其本身在内的任何数。
正无穷大于包括其本身在内的任何数。
[b]相等运算符 (==、!=) [/b]
如果两表达式的类型不同,则试图将它们转换为字符串、数字或 Boolean 量。
NaN 与包括其本身在内的任何值都不相等。
负零等于正零。
null 与 null 和 undefined 相等。
相同的字符串、数值上相等的数字、相同的对象、相同的 Boolean 值或者(当类型不同时)能被强制转化为上述情况之一,均被认为是相等的。
其他比较均被认为是不相等的。
[b]恒等运算符 (===、!==) [/b]
除了不进行类型转换,并且类型必须相同以外,这些运算符与相等运算符的作用是一样的。 [/size]
#include <stdio.h> #include <stdlib.h> #include "include/aip_common.h" #include "include/dynamic_array.h" #include "include/search_functions.h" #define BUFFER_SIZE 512 /*===================================================================================================================================*/ /* Function Name: v_s_main_print_int */ /* --------------------------------------------------------------------------------------------------------------------------------- */ /* Description: Prints an integer element from void pointer */ /* Arguments: VDP vdp_a_elem : Void pointer to integer element */ /* Return: void */ /*===================================================================================================================================*/ static void v_s_main_print_int(VDP vdp_a_elem) { printf("%d", *(S4 *)vdp_a_elem); } /*===================================================================================================================================*/ /* Function Name: v_s_main_print_float */ /* --------------------------------------------------------------------------------------------------------------------------------- */ /* Description: Prints a float element from void pointer */ /* Arguments: VDP vdp_a_elem : Void pointer to float element */ /* Return: void */ /*===================================================================================================================================*/ static void v_s_main_print_float(VDP vdp_a_elem) { printf("%.2f", *(float *)vdp_a_elem); } /*===================================================================================================================================*/ /* Function Name: v_s_main_print_char */ /* --------------------------------------------------------------------------------------------------------------------------------- */ /* Description: Prints a character element from void pointer */ /* Arguments: VDP vdp_a_elem : Void pointer to character element */ /* Return: void */ /*===================================================================================================================================*/ static void v_s_main_print_char(VDP vdp_a_elem) { printf("'%c'", *(S1 *)vdp_a_elem); } /*===================================================================================================================================*/ /* Function Name: v_s_main_print_array */ /* --------------------------------------------------------------------------------------------------------------------------------- */ /* Description: Prints contents of dynamic array */ /* Arguments: const ST_DA_ARRAY *stp_a_arr : Pointer to dynamic array structure */ /* void (*vfp_a_print_element)(VDP) : Function pointer for element printing */ /* Return: void */ /*===================================================================================================================================*/ static void v_s_main_print_array(const ST_DA_ARRAY *stp_a_arr, void (*vfp_a_print_element)(VDP)) { U4 u4_t_main_i; printf("["); for (u4_t_main_i = U4_MIN; u4_t_main_i < stp_a_arr->u4_s_size; u4_t_main_i++) { VDP vdp_t_main_elem = (U1 *)stp_a_arr->vdp_a_data + u4_t_main_i * stp_a_arr->u4_s_elem_size; vfp_a_print_element(vdp_t_main_elem); if (u4_t_main_i < stp_a_arr->u4_s_size - 1) { printf(", "); } } printf("]\n"); } /*===================================================================================================================================*/ /* Function Name: v_s_main_parse_int_array */ /* --------------------------------------------------------------------------------------------------------------------------------- */ /* Description: Parses integer input into dynamic array */ /* Arguments: ST_DA_ARRAY *stp_a_arr : Pointer to dynamic array structure */ /* Return: void */ /*===================================================================================================================================*/ static void v_s_main_parse_int_array(ST_DA_ARRAY *stp_a_arr) { U1 u1_t_main_buffer[BUFFER_SIZE]; S4 s4_t_main_value; U1 *u1p_t_main_token; printf("Enter integers separated by spaces: "); fgets((S1 *)u1_t_main_buffer, BUFFER_SIZE, stdin); u1p_t_main_token = (U1 *)strtok((S1 *)u1_t_main_buffer, " "); while (u1p_t_main_token != NULL) { s4_t_main_value = atoi((S1 *)u1p_t_main_token); v_g_da_push_back(stp_a_arr, &s4_t_main_value); u1p_t_main_token = (U1 *)strtok(NULL, " "); } } /*===================================================================================================================================*/ /* Function Name: v_s_main_parse_float_array */ /* --------------------------------------------------------------------------------------------------------------------------------- */ /* Description: Parses float input into dynamic array */ /* Arguments: ST_DA_ARRAY *stp_a_arr : Pointer to dynamic array structure */ /* Return: void */ /*===================================================================================================================================*/ static void v_s_main_parse_float_array(ST_DA_ARRAY *stp_a_arr) { U1 u1_t_main_buffer[BUFFER_SIZE]; float f_t_main_value; U1 *u1p_t_main_token; printf("Enter floating-point numbers separated by spaces: "); fgets((S1 *)u1_t_main_buffer, BUFFER_SIZE, stdin); u1p_t_main_token = (U1 *)strtok((S1 *)u1_t_main_buffer, " "); while (u1p_t_main_token != NULL) { f_t_main_value = atof((S1 *)u1p_t_main_token); v_g_da_push_back(stp_a_arr, &f_t_main_value); u1p_t_main_token = (U1 *)strtok(NULL, " "); } } /*===================================================================================================================================*/ /* Function Name: v_s_main_parse_char_array */ /* --------------------------------------------------------------------------------------------------------------------------------- */ /* Description: Parses character input into dynamic array */ /* Arguments: ST_DA_ARRAY *stp_a_arr : Pointer to dynamic array structure */ /* Return: void */ /*===================================================================================================================================*/ static void v_s_main_parse_char_array(ST_DA_ARRAY *stp_a_arr) { U1 u1_t_main_buffer[BUFFER_SIZE]; U4 u4_t_main_i; S1 s1_t_main_value; printf("Enter characters without spaces: "); fgets((S1 *)u1_t_main_buffer, BUFFER_SIZE, stdin); for (u4_t_main_i = U4_MIN; u4_t_main_i < BUFFER_SIZE; u4_t_main_i++) { s1_t_main_value = u1_t_main_buffer[u4_t_main_i]; if (s1_t_main_value == '\n' || s1_t_main_value == '\0') { break; } v_g_da_push_back(stp_a_arr, &s1_t_main_value); } } /*===================================================================================================================================*/ /* Function Name: main */ /* --------------------------------------------------------------------------------------------------------------------------------- */ /* Description: Main program for dynamic array operations */ /* Arguments: void */ /* Return: S4 : Exit status */ /*===================================================================================================================================*/ S4 main(void) { S4 s4_t_main_choice = S4_MIN; U1 u1_t_main_exit_flag = FALSE; while (!u1_t_main_exit_flag) { printf("\n===== Dynamic Array Program =====\n"); printf("1. Integer Sorting and Binary Search\n"); printf("2. Float Sorting and Binary Search\n"); printf("3. Character Sorting and Binary Search\n"); printf("4. Exit Program\n"); printf("Please select an option (1-4): "); scanf("%d", &s4_t_main_choice); getchar(); if (s4_t_main_choice == 4) { printf("Exiting program.\n"); u1_t_main_exit_flag = TRUE; continue; } ST_DA_ARRAY st_t_main_array; void (*vfp_t_main_print_element)(VDP) = NULL; S4 (*s4fp_t_main_compare)(const VDP, const VDP) = NULL; void (*vfp_t_main_parse_array)(ST_DA_ARRAY *) = NULL; U1 u1_t_main_found = FALSE; U1 u1_t_main_buffer[BUFFER_SIZE]; switch (s4_t_main_choice) { case 1: v_g_da_init(&st_t_main_array, sizeof(S4)); vfp_t_main_print_element = v_s_main_print_int; s4fp_t_main_compare = s4_g_comp_int; vfp_t_main_parse_array = v_s_main_parse_int_array; break; case 2: v_g_da_init(&st_t_main_array, sizeof(float)); vfp_t_main_print_element = v_s_main_print_float; s4fp_t_main_compare = s4_g_comp_float; vfp_t_main_parse_array = v_s_main_parse_float_array; break; case 3: v_g_da_init(&st_t_main_array, sizeof(S1)); vfp_t_main_print_element = v_s_main_print_char; s4fp_t_main_compare = s4_g_comp_char; vfp_t_main_parse_array = v_s_main_parse_char_array; break; default: printf("Invalid choice. Please select a valid option.\n"); continue; } vfp_t_main_parse_array(&st_t_main_array); printf("Original array: "); v_s_main_print_array(&st_t_main_array, vfp_t_main_print_element); printf("Sorting the array...\n"); v_g_da_bubble_sort(&st_t_main_array, s4fp_t_main_compare); printf("Sorted array: "); v_s_main_print_array(&st_t_main_array, vfp_t_main_print_element); printf("Enter the value to search: "); fgets((S1 *)u1_t_main_buffer, BUFFER_SIZE, stdin); if (s4_t_main_choice == 1) { S4 s4_t_main_target = atoi((S1 *)u1_t_main_buffer); u1_t_main_found = u4_g_search_binary(&st_t_main_array, &s4_t_main_target, s4fp_t_main_compare); } else if (s4_t_main_choice == 2) { float f_t_main_target = atof((S1 *)u1_t_main_buffer); u1_t_main_found = u4_g_search_binary(&st_t_main_array, &f_t_main_target, s4fp_t_main_compare); } else if (s4_t_main_choice == 3) { S1 st_t_main_target = u1_t_main_buffer[0]; u1_t_main_found = u4_g_search_binary(&st_t_main_array, &st_t_main_target, s4fp_t_main_compare); } if (u1_t_main_found) { printf("Value found in the array!\n"); } else { printf("Value not found in the array.\n"); } v_g_da_free(&st_t_main_array); } return 0; } 修改,增强健壮性,给出完整代码
09-11
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值