首页 > 其他分享 >C语言之用链表的方式解析与运算简单的波兰表达式

C语言之用链表的方式解析与运算简单的波兰表达式

时间:2024-11-30 13:04:38浏览次数:11  
标签:tmp node ExprNode rs expr express C语言 链表 表达式

C语言之用链表的方式解析与运算简单的波兰表达式

我这里说的简单的波兰表达式,是指没有嵌套的加减乘除表达式,
如: (+ 1 2), (- 100 90 5)

定义基本的数据结构

  • 定义数据类型,全用大写字母,DT开头,后面附加类型名字:DT_OPERATOR
  • 定义表达式结构体,Express,自定义为Expr
  • 定义链表节点结构体,ExpressNode,自定义为ExprNode
  • 定义逐项遍历操作用到的函数指针EPFunc
    代码如下:
/* define express datatype */
#define DT_OPERATOR 0X01
#define DT_INTEGER 0X02

/* define express struct */
typedef struct _Express Expr;
struct _Express {
  char dt; //express datatype
  union {
    char  oval; //operator
    long  ival; //integer
  } V;
};

/* define express node struct */
typedef struct _ExpressNode ExprNode;
struct _ExpressNode {
  Expr expr;
  ExprNode *next;
};

/* define function pointer for express node */
typedef void (*EPFunc) (Expr expr);

实现链表的基本功能:创建、释放、追加、逐项

  • 创建节点函数,创建运算符节点:expr_node_new_op,创建整数节点:expr_node_new_int
  • 释放节点函数 expr_node_free
  • 追加节点函数 expr_node_append
  • 逐项遍历函数 expr_node_foreach
    代码如下:
/* create a new operator express node */
ExprNode *
expr_node_new_op (char val)
{
  ExprNode *node = (ExprNode*) malloc (sizeof(ExprNode));
  node->expr.dt = DT_OPERATOR;
  node->expr.V.oval = val;
  node->next = NULL;
  return node;
}

/* create a new integer express node */
ExprNode *
expr_node_new_int (long val)
{
  ExprNode *node = (ExprNode*) malloc (sizeof(ExprNode));
  node->expr.dt = DT_INTEGER;
  node->expr.V.ival = val;
  node->next = NULL;
  return node;
}

/* free the express node list */
void
expr_node_free (ExprNode *node)
{
  while (node != NULL)
    {
      ExprNode *tmp = node->next;
      free (node);
      node = tmp;
    }
}

/* append node to head */
ExprNode *
expr_node_append (ExprNode *head, ExprNode *node)
{
  ExprNode *tmp = head;
  if (tmp == NULL) return node;
  while (tmp->next != NULL)
    tmp = tmp->next;
  tmp->next = node;
  return head;
}

/* foreach node call epfunc from head to end */
void
expr_node_foreach (ExprNode *head, EPFunc epfunc)
{
  ExprNode *tmp = head;
  while (tmp != NULL)
    {
      epfunc (tmp->expr);
      tmp = tmp->next;
    }
}

实现基本的运算功能:加、减、乘、除

  • 加法运算函数:expr_node_opadd
  • 减法运算函数:expr_node_opsub
  • 乘法运算函数:expr_node_opmul
  • 除法运算函数:expr_node_opdiv

代码如下:

/* compute express list */
/* declare here */
long
expr_node_compute (ExprNode *head);

/* run operator + return long int */
static long
expr_node_opadd (ExprNode *node)
{
  long rs = 0;
  ExprNode *tmp = node;
  if (tmp == NULL) return rs; //(+) return 0
  if (tmp->expr.dt == DT_INTEGER)
    { rs = tmp->expr.V.ival; }
  tmp = tmp->next;
  while (tmp != NULL)
    {
      if (tmp->expr.dt == DT_INTEGER)
	{
	  rs = rs + tmp->expr.V.ival;
	}
      tmp = tmp->next;
    }
  //printf ("OP add, RS : %ld\n", rs);
  return rs;
}

/* run operator - return long int */
static long
expr_node_opsub (ExprNode *node)
{
  long rs = 0;
  ExprNode *tmp = node;
  if (tmp == NULL) return rs; //(-) ??? out err info
  if (tmp->expr.dt == DT_INTEGER)
    { rs = tmp->expr.V.ival; }
  tmp = tmp->next;
  if (tmp == NULL) return -rs; //(- 9) ==> -9
  while (tmp != NULL)
    {
      if (tmp->expr.dt == DT_INTEGER)
	{
	  rs = rs - tmp->expr.V.ival;
	}
      tmp = tmp->next;
    }
  //printf ("OP sub, RS : %ld\n", rs);
  return rs;
}

/* run operator * return long int */
static long
expr_node_opmul (ExprNode *node)
{
  long rs = 0;
  ExprNode *tmp = node;
  if (tmp == NULL) return 1;  //(*) return 1;
  if (tmp->expr.dt == DT_INTEGER)
    { rs = tmp->expr.V.ival; }
  tmp = tmp->next;
  while (tmp != NULL)
    {
      if (tmp->expr.dt == DT_INTEGER)
	{
	  rs = rs * tmp->expr.V.ival;
	}
      tmp = tmp->next;
    }
  //printf ("OP mul, RS : %ld\n", rs);
  return rs;
}

/* run operator / return long int */
static long
expr_node_opdiv (ExprNode *node)
{
  long rs = 1;
  ExprNode *tmp = node;
  if (tmp == NULL) return rs; //(/) ??? out err info
  if (tmp->expr.dt == DT_INTEGER)
    { rs = tmp->expr.V.ival; }
  tmp = tmp->next;
  while (tmp != NULL)
    {
      if (tmp->expr.dt == DT_INTEGER)
	{
	  rs = rs / tmp->expr.V.ival;
	}
      tmp = tmp->next;
    }
  //printf ("OP div, RS : %ld\n", rs);
  return rs;
}

/* compute express list */
long
expr_node_compute (ExprNode *node)
{
  long rs = 0;
  ExprNode *tmp = node;
  switch (tmp->expr.V.oval)
    {
    case '+': rs = expr_node_opadd (tmp->next); break;
    case '-': rs = expr_node_opsub (tmp->next); break;
    case '*': rs = expr_node_opmul (tmp->next); break;
    case '/': rs = expr_node_opdiv (tmp->next); break;
    }
  return rs;
}

实现基本的信息输出功能,输出值和输出类型、值

  • 输出值函数:out_expr_value
  • 输出类型和值函数:out_expr_info
  • 输出表达式函数:out_express
  • 输出表达式信息函数:out_expinfo

代码如下:

/* declare out_expinfo */
void
out_expinfo (ExprNode *head);

/* declare out_express */
void
out_express (ExprNode *head);

/* output express info */
void
out_expr_info (Expr expr)
{
  switch (expr.dt)
    {
    case DT_OPERATOR: printf (" OP: %c\n",  expr.V.oval); break;
    case DT_INTEGER : printf ("INT: %ld\n", expr.V.ival); break;
    }
}

/* output express value */
void
out_expr_value (Expr expr)
{
  switch (expr.dt)
    {
    case DT_OPERATOR: printf (" %c",  expr.V.oval); break;
    case DT_INTEGER : printf (" %ld", expr.V.ival); break;
    }
}

/* output full express info */
void
out_expinfo (ExprNode *head)
{
  expr_node_foreach (head, out_expr_info);
}

/* output full express value */
void
out_express (ExprNode *head)
{
  printf (" (");
  expr_node_foreach (head, out_expr_value);
  printf (" )");
}

解析波兰表达式,将各个节点存入链表

  • 宏定义NBSIZE,指定保存数字的数组长度,即数的位数
  • parse_expr_string函数的参数是波兰表达式字符串
  • 返回值是链表节点指针

代码如下:

/* define number length */
#define NBSIZE 32

/* parse express string to express node */
ExprNode *
parse_expr_string (char *estr)
{
  ExprNode *root = NULL;
  char nbuf[NBSIZE] = {0};
  int idx = 0, ndx = 1, lv = 0;
  char c;

  nbuf[0] = '+'; //default +
  c = estr[idx];
  while (c != 0)
    {
      switch (c)
	{
	case '0'...'9': //number
	  {
	    char n = estr[idx+1];
	    nbuf[ndx] = c; ndx++;
	    if (n == ' ' || n == ')')
	      {
		long lt = strtol (nbuf, NULL, 10);
		ExprNode *tmp = expr_node_new_int (lt);
		root = expr_node_append (root, tmp);
		memset (nbuf, 0, NBSIZE); nbuf[0] = '+'; ndx = 1;
	      }
	  }
	  break;

	case '+': case '-': case '*': case '/': //operator
	  {
	    if (c == '+' || c == '-')
	      {
		char n = estr[idx+1];
		if (n >= '0' && n <= '9')
		  {
		    nbuf[0] = c; break;
		  }
	      }
	    ExprNode *tmp = expr_node_new_op (c);
	    root = expr_node_append (root, tmp);
	  }
	  break;

	case '(':
	  { lv++; } //todo
	  break;

	case ')':
	  {
	    lv--;
	    if (lv == 0) { return root; } //todo
	  }
	  break;

	case ' ': //space
	  break;

	defualt:
	  printf ("Error: Syntax error!\n");
	}

      idx++; c = estr[idx];
    }

  return root;
}

测试解析加法波兰表达式字符串函数

代码如下:

/* test function */
void
test_parse (void)
{
  //char *str = "(+ 10 20 30 40 50)";
  //char *str = "(+ 2 3 4)";
  //char *str = "(+ 2 3)";
  //char *str = "(+ 2)";
  //char *str = "(/)";  //out err info, need arg
  //char *str = "(*)";  //return 1
  //char *str = "(-)";  //out err info, need arg
  char *str = "(+)";  //return 0
  ExprNode *head;
  head = parse_expr_string (str);

  printf (" express : %s\n", str);
  printf ("-------------------------\n");
  out_expinfo (head);
  printf ("-------------------------\n");
  printf ("full expr:");
  out_express (head);
  printf ("\n-------------------------\n");
  printf ("Result : %ld\n", expr_node_compute (head));

  expr_node_free (head);
}

/**/
int
main (int argc, char *argv[])
{
  test_parse ();
  return 0;
}
//-----(+ 1 2)-----//

编译运行,结果如下:

gwsong@ubuntu:~/works/notes/lisp$ gcc xa.c -o xa
gwsong@ubuntu:~/works/notes/lisp$ ./xa
 express : (+ 10 20 30 40 50)
-------------------------
 OP: +
INT: 10
INT: 20
INT: 30
INT: 40
INT: 50
-------------------------
full expr: ( + 10 20 30 40 50 )
-------------------------
Result : 150
gwsong@ubuntu:~/works/notes/lisp$ gcc xa.c -o xa
gwsong@ubuntu:~/works/notes/lisp$ ./xa
 express : (+ 2 3 4)
-------------------------
 OP: +
INT: 2
INT: 3
INT: 4
-------------------------
full expr: ( + 2 3 4 )
-------------------------
Result : 9
gwsong@ubuntu:~/works/notes/lisp$ gcc xa.c -o xa
gwsong@ubuntu:~/works/notes/lisp$ ./xa
 express : (+ 2 3)
-------------------------
 OP: +
INT: 2
INT: 3
-------------------------
full expr: ( + 2 3 )
-------------------------
Result : 5
gwsong@ubuntu:~/works/notes/lisp$ gcc xa.c -o xa
gwsong@ubuntu:~/works/notes/lisp$ ./xa
 express : (+ 2)
-------------------------
 OP: +
INT: 2
-------------------------
full expr: ( + 2 )
-------------------------
Result : 2
gwsong@ubuntu:~/works/notes/lisp$ gcc xa.c -o xa
gwsong@ubuntu:~/works/notes/lisp$ ./xa
 express : (+)
-------------------------
 OP: +
-------------------------
full expr: ( + )
-------------------------
Result : 0
gwsong@ubuntu:~/works/notes/lisp$ 

测试解析减法波兰表达式字符串

字符串定义如下:

  //char *str = "(- 1000 500 100 50 10 5)";
  //char *str = "(- 10 5 1)";
  //char *str = "(- 3 2)";
  char *str = "(- 3)";
  //char *str = "(-)";  //out err info, need arg

编译运行,结果如下:

gwsong@ubuntu:~/works/notes/lisp$ gcc xa.c -o xa
gwsong@ubuntu:~/works/notes/lisp$ ./xa
 express : (- 1000 500 100 50 10 5)
-------------------------
 OP: -
INT: 1000
INT: 500
INT: 100
INT: 50
INT: 10
INT: 5
-------------------------
full expr: ( - 1000 500 100 50 10 5 )
-------------------------
Result : 335
gwsong@ubuntu:~/works/notes/lisp$ gcc xa.c -o xa
gwsong@ubuntu:~/works/notes/lisp$ ./xa
 express : (- 10 5 1)
-------------------------
 OP: -
INT: 10
INT: 5
INT: 1
-------------------------
full expr: ( - 10 5 1 )
-------------------------
Result : 4
gwsong@ubuntu:~/works/notes/lisp$ gcc xa.c -o xa
gwsong@ubuntu:~/works/notes/lisp$ ./xa
 express : (- 3 2)
-------------------------
 OP: -
INT: 3
INT: 2
-------------------------
full expr: ( - 3 2 )
-------------------------
Result : 1
gwsong@ubuntu:~/works/notes/lisp$ gcc xa.c -o xa
gwsong@ubuntu:~/works/notes/lisp$ ./xa
 express : (- 3)
-------------------------
 OP: -
INT: 3
-------------------------
full expr: ( - 3 )
-------------------------
Result : -3
gwsong@ubuntu:~/works/notes/lisp$ 
  • 只测试了加减法,只有减号时没有提示信息,以后还要完善,包含两个数:分数和复数!!!
  • 下一步研究一下波兰表达式嵌套问题,这样的: (+ 1 (+ 2 3)) !!!

完整代码如下:

/* filename: xa.c */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* compile : gcc xa.c -o xa */
/*     run : ./xa           */

/* define express datatype */
#define DT_OPERATOR 0X01
#define DT_INTEGER  0X02

/* define express struct */
typedef struct _Express Expr;
struct _Express {
  char dt; //express datatype
  union {
    char  oval; //operator
    long  ival; //integer
  } V;
};

/* define express node struct */
typedef struct _ExpressNode ExprNode;
struct _ExpressNode {
  Expr expr;
  ExprNode *next;
};

/* define function pointer for express node */
typedef void (*EPFunc) (Expr expr);

/* create a new operator express node */
ExprNode *
expr_node_new_op (char val)
{
  ExprNode *node = (ExprNode*) malloc (sizeof(ExprNode));
  node->expr.dt = DT_OPERATOR;
  node->expr.V.oval = val;
  node->next = NULL;
  return node;
}

/* create a new integer express node */
ExprNode *
expr_node_new_int (long val)
{
  ExprNode *node = (ExprNode*) malloc (sizeof(ExprNode));
  node->expr.dt = DT_INTEGER;
  node->expr.V.ival = val;
  node->next = NULL;
  return node;
}

/* free the express node list */
void
expr_node_free (ExprNode *node)
{
  while (node != NULL)
    {
      ExprNode *tmp = node->next;
      free (node);
      node = tmp;
    }
}

/* append node to head */
ExprNode *
expr_node_append (ExprNode *head, ExprNode *node)
{
  ExprNode *tmp = head;
  if (tmp == NULL) return node;
  while (tmp->next != NULL)
    tmp = tmp->next;
  tmp->next = node;
  return head;
}

/* foreach node call epfunc from head to end */
void
expr_node_foreach (ExprNode *head, EPFunc epfunc)
{
  ExprNode *tmp = head;
  while (tmp != NULL)
    {
      epfunc (tmp->expr);
      tmp = tmp->next;
    }
}

/* compute express list */
/* declare here */
long
expr_node_compute (ExprNode *head);

/* run operator + return long int */
static long
expr_node_opadd (ExprNode *node)
{
  long rs = 0;
  ExprNode *tmp = node;
  if (tmp == NULL) return rs; //(+) return 0
  if (tmp->expr.dt == DT_INTEGER)
    { rs = tmp->expr.V.ival; }
  tmp = tmp->next;
  while (tmp != NULL)
    {
      if (tmp->expr.dt == DT_INTEGER)
	{
	  rs = rs + tmp->expr.V.ival;
	}
      tmp = tmp->next;
    }
  //printf ("OP add, RS : %ld\n", rs);
  return rs;
}

/* run operator - return long int */
static long
expr_node_opsub (ExprNode *node)
{
  long rs = 0;
  ExprNode *tmp = node;
  if (tmp == NULL) return rs; //(-) ??? out err info
  if (tmp->expr.dt == DT_INTEGER)
    { rs = tmp->expr.V.ival; }
  tmp = tmp->next;
  if (tmp == NULL) return -rs; //(- 9) ==> -9
  while (tmp != NULL)
    {
      if (tmp->expr.dt == DT_INTEGER)
	{
	  rs = rs - tmp->expr.V.ival;
	}
      tmp = tmp->next;
    }
  //printf ("OP sub, RS : %ld\n", rs);
  return rs;
}

/* run operator * return long int */
static long
expr_node_opmul (ExprNode *node)
{
  long rs = 0;
  ExprNode *tmp = node;
  if (tmp == NULL) return 1;  //(*) return 1;
  if (tmp->expr.dt == DT_INTEGER)
    { rs = tmp->expr.V.ival; }
  tmp = tmp->next;
  while (tmp != NULL)
    {
      if (tmp->expr.dt == DT_INTEGER)
	{
	  rs = rs * tmp->expr.V.ival;
	}
      tmp = tmp->next;
    }
  //printf ("OP mul, RS : %ld\n", rs);
  return rs;
}

/* run operator / return long int */
static long
expr_node_opdiv (ExprNode *node)
{
  long rs = 1;
  ExprNode *tmp = node;
  if (tmp == NULL) return rs; //(/) ??? out err info
  if (tmp->expr.dt == DT_INTEGER)
    { rs = tmp->expr.V.ival; }
  tmp = tmp->next;
  while (tmp != NULL)
    {
      if (tmp->expr.dt == DT_INTEGER)
	{
	  rs = rs / tmp->expr.V.ival;
	}
      tmp = tmp->next;
    }
  //printf ("OP div, RS : %ld\n", rs);
  return rs;
}

/* compute express list */
long
expr_node_compute (ExprNode *node)
{
  long rs = 0;
  ExprNode *tmp = node;
  switch (tmp->expr.V.oval)
    {
    case '+': rs = expr_node_opadd (tmp->next); break;
    case '-': rs = expr_node_opsub (tmp->next); break;
    case '*': rs = expr_node_opmul (tmp->next); break;
    case '/': rs = expr_node_opdiv (tmp->next); break;
    }
  return rs;
}

/* declare out_expinfo */
void
out_expinfo (ExprNode *head);

/* declare out_express */
void
out_express (ExprNode *head);

/* output express info */
void
out_expr_info (Expr expr)
{
  switch (expr.dt)
    {
    case DT_OPERATOR: printf (" OP: %c\n",  expr.V.oval); break;
    case DT_INTEGER : printf ("INT: %ld\n", expr.V.ival); break;
    }
}

/* output express value */
void
out_expr_value (Expr expr)
{
  switch (expr.dt)
    {
    case DT_OPERATOR: printf (" %c",  expr.V.oval); break;
    case DT_INTEGER : printf (" %ld", expr.V.ival); break;
    }
}

/* output full express info */
void
out_expinfo (ExprNode *head)
{
  expr_node_foreach (head, out_expr_info);
}

/* output full express value */
void
out_express (ExprNode *head)
{
  printf (" (");
  expr_node_foreach (head, out_expr_value);
  printf (" )");
}

/* define number length */
#define NBSIZE 32

/* parse express string to express node */
ExprNode *
parse_expr_string (char *estr)
{
  ExprNode *root = NULL;
  char nbuf[NBSIZE] = {0};
  int idx = 0, ndx = 1, lv = 0;
  char c;

  nbuf[0] = '+'; //default +
  c = estr[idx];
  while (c != 0)
    {
      switch (c)
	{
	case '0'...'9': //number
	  {
	    char n = estr[idx+1];
	    nbuf[ndx] = c; ndx++;
	    if (n == ' ' || n == ')')
	      {
		long lt = strtol (nbuf, NULL, 10);
		ExprNode *tmp = expr_node_new_int (lt);
		root = expr_node_append (root, tmp);
		memset (nbuf, 0, NBSIZE); nbuf[0] = '+'; ndx = 1;
	      }
	  }
	  break;

	case '+': case '-': case '*': case '/': //operator
	  {
	    if (c == '+' || c == '-')
	      {
		char n = estr[idx+1];
		if (n >= '0' && n <= '9')
		  {
		    nbuf[0] = c; break;
		  }
	      }
	    ExprNode *tmp = expr_node_new_op (c);
	    root = expr_node_append (root, tmp);
	  }
	  break;

	case '(':
	  { lv++; } //todo
	  break;

	case ')':
	  {
	    lv--;
	    if (lv == 0) { return root; } //todo
	  }
	  break;

	case ' ': //space
	  break;

	defualt:
	  printf ("Error: Syntax error!\n");
	}

      idx++; c = estr[idx];
    }

  return root;
}

/* test function */
void
test_parse (void)
{
  //char *str = "(+ 10 20 30 40 50)";
  //char *str = "(+ 2 3 4)";
  //char *str = "(+ 2 3)";
  //char *str = "(+ 2)";
  //char *str = "(/)";  //out err info, need arg
  //char *str = "(*)";  //return 1
  //char *str = "(-)";  //out err info, need arg
  //char *str = "(+)";  //return 0
  //char *str = "(- 1000 500 100 50 10 5)";
  //char *str = "(- 10 5 1)";
  //char *str = "(- 3 2)";
  char *str = "(- 3)";
  ExprNode *head;
  head = parse_expr_string (str);

  printf (" express : %s\n", str);
  printf ("-------------------------\n");
  out_expinfo (head);
  printf ("-------------------------\n");
  printf ("full expr:");
  out_express (head);
  printf ("\n-------------------------\n");
  printf ("Result : %ld\n", expr_node_compute (head));

  expr_node_free (head);
}

/**/
int
main (int argc, char *argv[])
{
  test_parse ();
  return 0;
}
//-----(+ 1 2)-----//

标签:tmp,node,ExprNode,rs,expr,express,C语言,链表,表达式
From: https://blog.csdn.net/gwsong52/article/details/144074222

相关文章

  • cron: 如何使用Cron表达式配置定时任务
    Cron表达式用于设置定时任务,无论是在Linux的Crontab中,还是在各种语言开发的程序中都有应用,它提供了一种强大而灵活的方法来设定定时任务。Cron表达式语法Cron表达式是一种字符串格式,标准的Cron表达式是由五部分组成,分别表示,分钟、小时、日期、月份和星期几。这个时候,就有小伙......
  • C语言经典例题-13
    1.小乐乐走台阶题目描述:小乐乐上课需要走n阶台阶,因为他腿比较长,所以每次可以选择走一阶或者走两阶,那么他一共有多少种走法?输入描述:输入包含一个整数n(1≤n≤30)输出描述:输出一个整数,即小乐乐可以走的方法数。示例1输入:2输出:2示例2输入:10......
  • C语言中的结构体
    一.结构体声明首先要知道结构的成员可以是标量、数组、指针,甚至是其他结构体。例如描述一个学生:structStu{charname[20];intage;charsex[5];};那么如何创建一个结构体变量?intmain(){structStua,b,c;return0;}或者structStu{charname[20];......
  • C语言实现数组堆并解决TopK问题
    还是先定义结构体typedefintHPDataType;typedefstruct{HPDataType*array;intsize;intcapacity;}HP;voidHeapInit(HP*php){assert(php);php->array=NULL;php->capacity=php->size=0;}首先是它的初始化。voidHeapDestroy......
  • 力扣876. 链表的中间结点
    文章目录一、快慢指针二、运行代码链表的中间结点一、快慢指针我们学习快慢指针,是为了这种算法思想。顾名思义,是一个慢指针,一步一步走。快指针随心所欲,可以一次走两步,也可以一次走三步四步等。如果一次走两步的话,当快指针走到链表尾部的时候,慢指针恰好可以走到链......
  • P5015 [NOIP2018 普及组] 标题统计 C语言
    先说思路:跟着题意来就好,其实更多的是考察fgets()函数的基础运用,之后用循环遍历字符串,若是遇到空格和换行符就不计入,反之count++;这里也可以直接用isalnum()直接对输入的字符是否是字母或是数字进行判断。以下是代码实现:#include<stdio.h>#include<ctype.h>intmain(){......
  • c语言动态通讯录
    首先我们得明确它的基本功能,信息:1.人的信息:姓名+年龄+性别+地址+电话2.通讯录的可以存放100个人的信息3.功能:1>增加联系人2>删除指定联系人3>查找指定联系人的信息4>修改指定联系人的信息5>显示所有联系人的信息6>排序(姓名,年龄)test.c 测试通讯录contact.c 通讯......
  • 代码随想录第十一天|栈与队列part02--150.逆波兰表达式求值、239.滑动窗口最大值、347
    150.逆波兰表达式求值(150.逆波兰表达式求值)题目分析:计算逆波兰表达式(后缀表达式:左右中)的值,算符仅包含四则运算,操作数为一个整数或另一个表达式,整数除法向零截断(向下取整),无除零运算,答案及中间结果不超过32位,即使用整型int即可。解题重点:后缀表达式的每一个表达式中:读入1个算......
  • 【Java】:lambda 表达式
     ......
  • C语言 - 指针,数组
    指针指针入门创建变量intage=10;创建指针,指向变量指针类型*指针变量=&变量int*p=&age;当有了指针之后,就可以通过指针操作他指向的数据了通过指针获取指向的位置的数据,在指针前面加一个*为解引用指针前加*修改,改的是指针指向的位置的值指针的作用:游......