206. 反转链表(c++/go)

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    ListNode* reverseList(ListNode* head) {
        if(head == nullptr){
            return nullptr;
        }
        ListNode* res = nullptr;
        while(head){
            ListNode* temp = head->next;//先储存下一个节点
            head->next = res;//把下一个节点指向res的nullptr指针
            res = head;//res指针往head移动
            head = temp;//head往后移
        }
        return res;


    }
};
#include<iostream>
using namespace std;

struct ListNode{
    int val;
    struct ListNode *next;
    ListNode():val(0),next(nullptr){};
    ListNode(int x):val(x),next(nullptr){};
};

class Solution {
public:
    ListNode* ReverseList(ListNode* pHead) {
    if(pHead == nullptr){
        return {};
    }
    ListNode* cur = nullptr;
    while(pHead){
        ListNode* temp = pHead->next;
        pHead->next = cur;
        cur = pHead;
        pHead = temp;
    }    
    while(cur){
        cout << cur->val<<" ";
        cur = cur->next;
    }
        return cur;
    
    }
};

int main(){
    int val;
    ListNode* head = new ListNode(0);
    ListNode* phead = head;
    while(cin >> val){
        ListNode* next_node = new ListNode(val);
        head = head -> next = next_node;
    }
    phead = phead->next;
//     while(phead){
//         cout << phead->val<<" ";
//         phead = phead->next;
//     }
    Solution s;
    s.ReverseList(phead);
    return 0;
}

go:

/**
 * Definition for singly-linked list.
 * type ListNode struct {
 *     Val int
 *     Next *ListNode
 * }
 */
func reverseList(head *ListNode) *ListNode {
    var cur *ListNode
    for head != nil{
        tmp := head.Next
        head.Next = cur
        cur = head
        head = tmp
    }
    return cur
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 需要安装Microsoft Visual C++ 14.,可以通过“Microsoft Visual C++ Build Tools”获取:https://visualstudio.microsoft.com/downloads/。 ### 回答2: Microsoft Visual C++ 14.0是在开发和编译用C++编写的应用程序时需要的一种编译器。这个编译器可以让开发者生成高效的机器代码,从而使得编写的程序可以在计算机上运行。 如果你在运行一个依赖于Microsoft Visual C++ 14.0的应用程序时遇到了“Microsoft Visual C++ 14.0 is required”的错误提示,那么你需要从官方网站上下载并安装Microsoft Visual C++ Build Tools(Microsoft Visual C++生成工具)来获得这个核心的编译器。 这个工具包包含了各种版本和组件的Microsoft Visual C++工具,包括Microsoft Visual C++ 14.0。它可以让你使用命令行来使用这些工具,也可以为你的开发环境提供必需的.NET框架和C++标准库。 要下载和安装Microsoft Visual C++ Build Tools,你需要进入Visual Studio的官方网站,并进入下载页面。在下载页面中你可以选择你需要的组件,比如编译器,SDK和其他的开发工具。你可以根据你的需要下载一些或者全部的组件。 安装完成后,你需要重新启动计算机,以使得新安装的组件可以在系统中生效。接下来,你就可以重新运行你的应用程序了,这个时候你将不再受到“Microsoft Visual C++ 14.0 is required”错误信息的限制了。 ### 回答3: 微软视觉 c 14.0 是一个用于开发 C++ 程序的工具包。它是 Microsoft Visual Studio 的一部分,主要用于编译和运行 C++ 代码。当你想要编写一个 C++ 程序时,微软视觉 c 14.0 是必不可少的工具。 若在 Windows 系统上安装某些软件时出现“microsoft visual c 14.0 is required”这样的提示,那么说明你的计算机缺少这个工具包。为了解决这个问题,你需要前往微软官网下载并安装微软视觉 c 14.0。 在微软官网上,你可以找到“microsoft visual c build tools”这个工具包。通过下载和安装这个工具包,你可以轻松地解决“microsoft visual c 14.0 is required”的问题。 需要注意的是,微软视觉 c 14.0 并不适用于所有版本的 Windows 操作系统。具体来说,它只能在 Windows 7 SP1 或更高版本的操作系统上使用。如果你的计算机运行的是旧版本的 Windows 操作系统,则需要升级到最新版本,然后再下载并安装微软视觉 c 14.0。 综上所述,微软视觉 c 14.0 是一个非常重要的工具包,它为 C++ 程序的开发和编译提供了强大的支持。如果你需要编写 C++ 程序,那么你必须下载并安装这个工具包。若出现“microsoft visual c 14.0 is required”的提示,则可以通过下载和安装“microsoft visual c build tools”来解决该问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值