0
点赞
收藏
分享

微信扫一扫

Flume学习笔记(4)—— Flume数据流监控

c一段旅程c 2023-11-18 阅读 45

在这里插入图片描述
实战一:
在这里插入图片描述
在这里插入图片描述

#include <cstddef>
class Partition {
public:
    ListNode* partition(ListNode* pHead, int x) {
        // write code here
        struct ListNode* head1,*head2,*tail1,*tail2;
        head1=tail1=(struct ListNode*)malloc(sizeof(struct ListNode));
        head2=tail2=(struct ListNode*)malloc(sizeof(struct ListNode));
        struct ListNode* cur=pHead;
        while(cur)
        {
            if(cur->val<x)
            {
                tail1->next=cur;
                tail1=tail1->next;
            }
            else 
            {
                tail2->next=cur;
                tail2=tail2->next;
            }
            cur=cur->next;
            
        }
        tail1->next=head2->next;
        tail2->next=NULL;
        pHead=head1->next;
        free(head1);
        free(head2);
        return pHead;

    }
};

实战二:
在这里插入图片描述

在这里插入图片描述

#include <cstddef>
class PalindromeList {
public:
struct ListNode* reverseList(struct ListNode* head) {
    struct ListNode* cur=head;
    struct ListNode* newhead=NULL;
    while(cur)
    {
     struct ListNode* next=cur->next;
     cur->next=newhead;
     newhead=cur;
     cur=next;
    }
    return newhead;
}
struct ListNode* middleNode(struct ListNode* head) {
    struct ListNode* slow=head;
    struct ListNode* fast=head;
    while(fast&&fast->next)
    {
        fast=fast->next->next;
        slow=slow->next;
    }
    return slow;
}
    bool chkPalindrome(ListNode* head) {
        // write code here
        struct ListNode* mid=middleNode(head);
        struct ListNode* rehead=reverseList(mid);
        while(head&&rehead)
        {
            if(head->val!=rehead->val)
            {
                return false;
            }
            head=head->next;
            rehead=rehead->next;
        }
        return true;
    }
};

如果对你们有帮助的话,就支持一下吧!

举报

相关推荐

0 条评论