单链表的实现和基本操作

/* *
* File: Main.c
* Descript: 单链表操作
* Author: Red_angelX
*/

# include <stdio.h>
#
define MAXNUM 100

/* *
* 学生结构体链表
*
*/
typedef struct student
{
    int 
number ;
    char name[
10 ];
    int score;
    
// 新增链表指针
    struct student *   next ;
}student;

/* *
* 创建链表
*
*/
student
*  create()
{
    int n
, i;
    student 
* head ,* preview ,* current ;     /*  head表头 preview前一个 current当前  */
    
if (( head  =  (student  * )(malloc( sizeof (student))))  ==   NULL )
    {
        
printf ( "          无法分配内存 " );
        
exit ( 0 );
    }
    head
-> next   =   NULL ;   /*  表头置空 初始化  */
    preview 
=  head;      /*  preview 指向表头  */

    
printf ( "            请输入学生数: " );
    scanf(
" %d " ,& n);
    
for (i = 0 ;i < n;i ++ )
    {
        
if ((  current   =  (student  * )(malloc( sizeof (student))))  ==   NULL )
        {
            
printf ( "         无法分配内存 " );
            
exit ( 0 );
        }
        preview
-> next   =   current ;       /* 把前一个节点指向当前节点,连接所有链表 */
        
printf ( "            请输入学生%d的数据: " , i + 1 );
        
printf ( "                     学号:  " );
        scanf(
" %d " ,& current -> number );
        
printf ( "                     姓名:  " );
        scanf(
" %s " ,& current -> name);
        
printf ( "                     成绩:  " );
        scanf(
" %d " ,& current -> score);
        
current -> next   =   NULL ;
        preview 
=   current ;   
    }
    
return  (head);
}

/* *
* 查找节点
*
*/
void find(student 
* stu)
{
    int x;
    student 
* head;
    
printf ( "           请输入要查找学生的学号: " );
    scanf(
" %d " ,& x);
    head 
=  stu;

    
while (head  &&  head -> number   !=  x)
    {
        head 
=  head -> next ;   /* 指向下条记录  */
    }
    
if (head)
    {
        
printf ( "  学号   姓名   成绩 " );
        
printf ( " %6d " ,  head -> number );
        
printf ( "    %s " , head -> name);
        
printf ( " %6d " ,  head -> score);        
    }
    
else
    {
        
printf ( "            没找到! " );
    }
}

/* *
*插入节点
*就当往最后插入了
*
*/
void insert(student 
* stu)
{
    int i
, n;
    student 
* head ,* current ;    
    
printf (            " 请插入学生数: " );
    scanf(
" %d " ,& n);
    head 
=  stu;
    
// 把head移动到最后
     while (head -> next  )
        head
= head -> next ;

    
for (i = 0 ;i < n;i ++ )
    {
        
if ((  current   =  (student  * )(malloc( sizeof (student))))  ==   NULL )
        {
            
printf ( "         无法分配内存 " );
            
exit ( 0 );
        }
        head
-> next   =   current ;
        
printf ( "            请输入学生%d的数据: " , i + 1 );
        
printf ( "                     学号:  " );
        scanf(
" %d " ,& current -> number );
        
printf ( "                     姓名:  " );
        scanf(
" %s " ,& current -> name);
        
printf ( "                     成绩:  " );
        scanf(
" %d " ,& current -> score);
        
current -> next   =   NULL ;
        head 
=   current ;
    }
}

/* *
* 删除节点
*
*/
void delete(student 
* stu)
{
    int x;
    student 
* head ,* temp;

    
printf ( "       输入要删除成绩学生的学号: " );
    scanf(
" %d " ,& x);
    head 
=  stu;

    
while (head -> next   &&  head -> next -> number   !=  x)
    {
        head 
=  head -> next ;   /* 指向下条记录  */
    }

    
if (head -> next )
    {
        temp 
=  head -> next ;
        head
-> next   =  head -> next -> next ;
        free(temp);
        
printf ( "      已删除! " );
    }
    
else
    {
        
printf ( "      无此学生成绩,无法删除! " ); 
    }
}

/* *
* 主函数,链表操作

* Author: Red_angelX
*/
void main()
{
    student 
* stu;
    int k;
    
while  ( 1 )
    {        
            
// clrscr();
             printf ( "              ******************************   " );
            
printf ( "             |           学生成绩管理        | " );
            
printf ( "             |*******************************| " );
            
printf ( "             |           1 登记成绩          | " );
            
printf ( "             |           2 查询成绩          | " );
            
printf ( "             |           3 插入成绩          | " );
            
printf ( "             |           4 删除成绩          | " );
            
printf ( "             |           0 退出程序          | " );
            
printf ( "             |*******************************| " );
            
printf ( "             |       Code By Red_angelX      | " );
             printf ( "               *******************************  " );
            
printf ( " " );
            
printf ( "             请输入选择的功能号: " );
            scanf(
" %d " ,& k);
            
switch (k)
            {
            
case   1 :  
                stu 
=  create();
                
break ;
            
case   2 :
                find(stu);
                
break ;
            
case   3 :  
                insert(stu);
                
break ;
            
case   4 :  
                delete(stu);
                
break ;
            
case   0 :   exit ( 0 );
            
default : printf ( " 选择错误! " );
            }
    }
        
}



 
03-28
### MCP API 的文档与使用教程 MCP 是一种用于增强大型语言模型 (LLM) 功能的技术框架,它通过提示(Prompts)、资源(Resources)以及工具(Tools)这三种核心原语来扩展 LLM 能力[^2]。Apifox 平台也认识到 MCP 技术在 API 开发领域的重要作用,并将其应用于实际场景中[^1]。 为了实现将 `/Users/syw/project/wechatAr` 文件夹下的所有文件上传至远程服务器 `47.93.xx.xx` 用户名 `root` 下的 `/opt/ll` 目录的操作,可以基于 MCP 工具功能构建一个自定义的服务逻辑。以下是具体实现方法: #### 实现方案 利用 SCP 命令完成文件传输任务,并结合 MCP 的 Tool 功能封装此操作以便于后续调用。当关键词为“上传微信目录”时,触发该工具执行相应动作。 ```python import subprocess def upload_wechat_directory(): source_dir = "/Users/syw/project/wechatAr/*" target_server = "root@47.93.xx.xx:/opt/ll/" try: result = subprocess.run(["scp", "-r", source_dir, target_server], check=True) return {"status": "success", "message": f"All files from {source_dir} have been uploaded to {target_server}"} except Exception as e: return {"status": "error", "message": str(e)} # 将上述函数注册为 MCP 中的一个 tool tools = { "upload_wechat_directory_tool": upload_wechat_directory, } # 定义 prompt 和 resource 配置部分省略... ``` 以上代码片段展示了如何创建一个名为 `upload_wechat_directory_tool` 的工具并将其集成到 MCP 系统里去[^3]。每当接收到匹配条件的消息比如含有特定关键字的时候就会激活对应的行为即启动SCP进程从而达成目标需求。 #### 进一步学习资料推荐 对于希望深入研究或者实践更多关于 MCP 应用案例的人士来说,《MCP 教程进阶篇》提供了丰富的实例分析和技术细节值得参考阅读;另外《MCP 极简入门:超快速上手运行简单的 MCP 服务和 MCP 客户端》同样是非常好的起点材料之一可以帮助初学者迅速掌握基础概念及其运作机制。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值