Ch2-1: de-duplicate a linked-list with/without additional buffer

java.io.IOException: Connection reset by peer 完整错误信息: java.io.IOException: Connection reset by peer at sun.nio.ch.FileDispatcherImpl.read0(Native Method) at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:39) at sun.nio.ch.IOUtil.r... 阅读详情

Chap 2 deal with linked-list. So I finished Xuetang

Ch2-1:

The different is the time complexity and the reason we use 2 poniters/3 pointers:

p is the base addr, q is the increased pointer;

c is the base-base addr, p is the base-increase pointer, q is the increased pointer.

//http://hawstein.com/posts/2.1.html
//http://en.cppreference.com/w/cpp/utility/hash

#include 
#include 
using namespace std;

struct node{
    int data;
    node *next;
};
bool hass[100];

node* init(int* a, int n){
    node *head, *p;
    for(int i=0; idata = a[i];
        if(i==0){
            head = p = nd;
            continue;
        }
        p->next = nd;
        p = nd;
    }
    return head;
}

void print(node *head){
    node* p;
    p = head;
    while(p){
        cout<data<<"_ ";
        p = p->next;
    }
    cout<< "ty" << endl;
}

void removedulicate(node *head){  // with buffer hass[100]--O[n]
    if(head==NULL) return;
    node *p=head, *q=head->next;
    hass[head->data] = true;
    while(q){
        if(hass[q->data]){
            node *t = q;
            p->next = q->next;
            q = p->next;
            delete t;
        }
        else{
            hass[q->data] = true;
            p = q; q = q->next;
        }
    }
}
void removedulicate1(node *head){  //without buffer  -- O[n^2]
    if(head==NULL) return;
    node *p, *q, *c=head;
    while(c){
        p=c; q=c->next;
        int d = c->data;
        while(q){
            if(q->data==d){
                node *t = q;
                p->next = q->next;
                q = q->next;
                delete t;
            }
            else{
                p = q; q = q->next;
            }
        }
        c = c->next;
    }
}

int main(){
    int n = 10;
    int a[] = {
        3, 2, 1, 3, 5, 6, 2, 6, 3, 1 
    };
    memset(hass, false, sizeof(hass));
    node *head = init(a, n);
    cout << head << " jg " << head->data <

如果在init 里面的最后两句这样改的话
p = p->next;
p = nd;
输出只有head
Executing the program....
$demo 
0x602010 jg 3
3_ ty
3_ ty

因为这样只是把p的后继指回给p,而不是更新。
正确的做法是:
p->next = nd; //将p的后继更新为new node;
p= nd; // 讲p(即地址)更新为这个new node。


Here is the output:
Compiling the source code....
$g++ -std=c++11 main.cpp -o demo -lm -pthread -lgmpxx -lgmp -lreadline 2>&1

Executing the program....
$demo 
0x602010 jg 3
3_ 2_ 1_ 3_ 5_ 6_ 2_ 6_ 3_ 1_ ty
3_ 2_ 1_ 5_ 6_ ty



【高分子材料工程】嵌件注塑结构设计与工艺优化:金属-塑料复合件界面强度及失效预防技术规范 内容概要:本文系统阐述了嵌件注塑(Insert Molding)的设计参数、模具关键技术及失效预防措施,聚焦黄铜H62或304不锈钢与PA66-GF30材料组合的基准工况,提供可用于工程图纸、DFM检查、模具验收和工艺规程的量化依据。内容涵盖工艺边界界定、材料匹配与界面力学分析、结构设计参数(如包覆壁厚、滚花、倒角)、模具设计要点(定位、浇口、排气、冷却)、工艺参数窗口、八大失效模式及其对策、验证验收标准以及量产控制要求,强调通过DFM仿真、模流分析和DOE试模优化工艺,并列出常见设计误区与纠正方案。; 适合人群:从事注塑产品设计、模具开发、工艺工程及质量管理的工程技术人员,尤其适用于汽车、电子、医疗等行业中具备1-3年及以上相关经验的研发人员; 使用场景及目标:①指导嵌件注塑零件的可制造性设计与结构优化;②支持模具设计评审与验收;③制定试模调机与量产工艺规范;④开展失效分析与质量改进; 阅读建议:此资源兼具理论机制与工程实践,建议结合实际项目对照查阅,重点关注包覆壁厚、预热温度、浇口布置等关键参数的取值边界,并在应用非基准材料时进行线膨胀系数与收缩率的换算修正,避免直接套用数据。 立即下载

相关推荐

智慧医共体AI大模型赋能智能体平台及AI场景应用规划方案(决策评审版).pptx

智慧医共体AI大模型赋能智能体平台及AI场景应用规划方案(决策评审版).pptx

cc150做题计划

计划:12.29.2013 - 1.29.2013 做完第一遍题目,然后2月做leetcode。 2月底面试前完成200题C++。 这里记录一下ctci学习的参考资料。 1. hawstein的blog 2. https://github.com/ChengTian/CtCI 3. absolute C++ 5th 4. Primer C++ 5. learncpp:http

纯黑老白的专栏 2909

14-15日周末听写音频.mp3

14-15日周末听写音频.mp3

ch4.6: find the LCA of 2 nodes in a binary tree with 3 different methods

In this problem, it is important to fully understand the definition of least common ancestor of 2 nodes: it means: (from leetcode blog: 点击打开链接) _______3______ / \

纯黑老白的专栏 1330

图腾柱无桥PFC变换器+平均电流控制+PI电压双闭环前馈控制设计(Simulink仿真实现)

内容概要:本文系统研究了图腾柱无桥PFC变换器的高效率控制策略,采用平均电流控制结合PI电压双闭环前馈控制,利用Simulink平台构建完整的系统仿真模型,涵盖主电路拓扑、控制环路设计、关键参数计算及动态性能验证。研究重点在于提升功率因数、降低输入电流谐波含量,并确保输出电压的高度稳定性。通过仿真分析,全面评估了系统在启动、稳态运行及抗干扰等方面的性能表现,充分展现了现代电力电子变换器在高效能、高可靠性方面的先进控制技术应用; 适合人群:具备一定电力电子技术基础和Simulink仿真能力的电气工程及相关专业的研究生、科研人员及企业研发工程师; 使用场景及目标:①研究高效率PFC变换器的控制策略;②掌握图腾柱无桥PFC电路的工作原理与建模方法;③开展新能源、电动汽车充电、工业电源等领域中高性能整流器的技术开发与性能优化; 阅读建议:建议读者结合Simulink仿真模型同步操作,重点关注控制环路的设计细节与参数整定过程,深入理解平均电流控制与双闭环前馈控制的协同机制,同时可拓展至不同工况下的性能测试以增强工程实践能力。

零信任架构实战:“持续验证+动态授权”全流程解析(附策略引擎联动图)

《零信任实战指南:7图拆解核心流程与行业案例》摘要:本文通过7张架构图系统解析零信任五大核心流程:强身份认证、设备检查、动态授权、持续监控和自动降权。对比金融(重数据审计)与制造业(重物理绑定)的落地差异,指出三大常见误区及解决方案。数据显示,零信任可使安全响应提速60%,泄露成本降低45%。文章提供6个月实施路线图,强调零信任是"智能信任"体系,建议企业分阶段改造,优先保护核心系统。附赠金融/制造行业策略模板及甘特图示例。(149字)

sara_han的博客 780

Ch1.6: IN-place-ly rotate a pic(NxN matrix) by 90 digree in Verilog(CPP)

这个有点像DSP FPGA Chang Choo的题目,一般是放大插值,DFT,IIR之类的Verilog题目。 题目在这:Given an image represented by an NxN matrix, where each pixel in the image is 4 bytes, write a method to rotate the image by 90 degrees.

纯黑老白的专栏 1295

citespace基本操作

聚类分析 时间线图 这些结果都是高被引文献的相关呈现结果,代表该领域的文献基础 下面可以看看该project的前沿领域 选择keywords 和term go! 调整显示方式 生成凸线图:表示 在某个研究领域或者时间段内 ,大家对某个领域或者某个词的关注度突然增高,凸显前沿方向的转变 以此来发现热点 ...

生信小博士的博客 1万+

Ch2-2: return the nth to the last node data of a singly linked list

In this problem, I need to find the nth to the last node data of a singly linked list.  In order to do so, one good way is to use recursion, since it is automatically put recursion part into stack an

纯黑老白的专栏 1290

单粒子翻转对FPGA的影响及解决方法

单粒子翻转对FPGA的影响及解决方法

航天领域资深码农,型号经验丰富,一线干货分享 2446

本科双非的计算机考研择校注意点——经验贴

一战一志愿上岸某211的电子信息专硕。之前在某乎也发过帖子。但现在用优快云,所以把相关的心得再发出来仅供大家参考。 首先,我认为最重要的是你为什么要考研? 不管你是为了混一个文凭将来好进大厂,还是为了真正搞学术或者学知识,你要知道你自己的目标,只有坚定自己的目标,才有动力去走完这段复习的历程。真正的考研,是很苦的。如果你是为了逃避大四面临的就业才选择考研,并且还浑浑噩噩不当回事,那我劝你放弃,不如踏踏实实学点技术去找实习。那从我自己出发,我是认为自己本科双非院校且自己四年间没有学到什么专业方面的技能,

m0_56698268的博客 3166

1/22/2014: 纪念第一个C++ programmer电面--F家

经过20天的CC刷题(其实是学习),才刚刚做到第四章。看看其他非ACM牛人,都是leetcode,CC,EPI滚瓜烂熟才去面。而且onsite确实是靠实力,要有做过大project之后才能真正融会贯通C++精神。 Anyway,谢谢郭志给的refer,不然连电面的机会都没有。 开头是C++基础题: 1. Fib的2种写法:recursive和DP 2. Struct和Class的区别;在C

纯黑老白的专栏 1274

基于LSTM语义分析的企业风险预测系统

在数字化时代,企业面临着前所未有的挑战和机遇,而风险管理作为确保企业稳定发展的关键一环,其重要性日益凸显。为了及时、准确地监测和分析企业相关的风险,并预测可能带来的风险,本文介绍了一种基于长短期记忆(LSTM)语义分析的企业风险预测系统。该系统利用深度学习技术,通过将收集到的企业数据进行预处理和分析,结合LSTM模型对文本进行深度语义分析,从而实现对潜在风险的预测和评估。系统设计方面,该系统包括数据预处理、LSTM模型构建与训练、风险预测以及可视化展示等模块。

qiufangtaowvnyyidtf的博客 1393

Ch1-7: clear the row i and column j iff a[i][j]==0

in this problem, both monish001 and hawstein use O(n^2) solution which first tranverse the char** a to find the a[i][j]==0 and mark that row/col to be: TRUE. Then the send loop make the TURE row/col

纯黑老白的专栏 1207

C#实践项目1

需求: 在CAD内实现两个坐标系的转换。 转换方式为文件内的所有图形从一个坐标系下的坐标,转换到另一个坐标系下的坐标。 进行坐标转换后,仅仅是坐标发生改变,图层、样式等等不会发生变化。

weixin_51182789的博客 5330

【STK】手把手教你利用STK进行导弹和反导仿真01 - STK/MMT模块安装部署

【STK】手把手教你利用STK进行导弹和反导仿真01 - STK/MMT模块安装部署MMT模块与STK的版本是一一对应的,比如我现在手上的版本是MMT9的,那么我使用的STK的版本也必须是9版本的,如果你现在正在使用的是更高版本的STK,比如说10、11.2、11.6、12.2,那么该怎么办呢?这个经本人尝试,目前是可以多个STK版本共存的,我们可以根据自己的需要安装多个版本的STK下面开始讲解具体的安装步骤,

weixin_44184852的博客 2920

复习一下dfs和bfs 用java

dfs 和 bfs都是用来找从source 到 target的path的算法。 dfs用的是recursion,bfs则用queue

纯黑老白的专栏 1191

TRAE智能体开发:TRAE概述

TRAE(/treɪ/)深度融合 AI 能力,是一名能够理解需求、调用工具并独立完成各类开发任务的“AI 开发工程师”,帮助你高效推进每一个项目。

王国平的博客 1288

Ch3-1: use a single array to implement three stacks.

Here it explains why Hawstein use this in his constructor, because he use size a parameter in his constructor while "size" is also a member variable(it's private), so he use this->size = size, explici

纯黑老白的专栏 1097

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

ch4.7: given 2 huge Binary tree t1, t2(>1millon nodes), decide if one tree is subtree of another one

// Ch4.7: You have two very large binary trees: T1, with millions of nodes, and T2, // with hundreds of nodes. Create an algorithm to decide if T2 is a subtree of T1 #include #include #includ

纯黑老白的专栏 1030

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

复习recursion

1. 如果这样 private void lop(int x, int size, double[] jerry){ if(x==size-1){ jerry[x] = -1; return; } if(jerry[x+1]==0){ jerry[x+1] = jerry[x]- 1; //if so, lop(x+1, size, jerry); }

纯黑老白的专栏 1009

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

Ch2-5: find the beginning of loop in a circular linked list---two solutions

Given a circular linked list, implement an algorithm which returns node at the beginning of the loop. DEFINITION Circular linked list: A (corrupt) linked list in which a node’s next pointer poin

纯黑老白的专栏 986

Ch3-2: implement min() for a stack with O(1)

Here will show the thinking flow from bad to good. idea 1: const int MAX_INT = ~(1<<31);//2147483647 struct node{ int val, min; }; class StackWithMin{ public: StackWithMin(int size){

纯黑老白的专栏 956

Ch8.8: 8 queen problem

In order to solve this problem efficiently, need to use backtracking method instead of iterations. Aka: Backtracking is a general algorithm for finding all (or some) solutions to some computational p

纯黑老白的专栏 949

Ch3-3: popat(int idx) of setofstack

Continue to use class to design solution, also, start to use STL, such as container (vector, stack, set, ...). save time and to be more professional. The design without popat method is similar to the

纯黑老白的专栏 948

Ch4-2: find if 2 given vertices are connected in a directed map,BFS + JUST fix the DFS recursion

In this problem, there are 2 ways: BFS or DFS. Hawstein used BFS: #include #include #include #include using namespace std; const int maxn = 100; bool g[maxn][maxn], visited[maxn]; int n;

纯黑老白的专栏 938
上一篇: Ch1-7: clear the row i and column j iff a[i][j]==0
下一篇: Ch2-2: return the nth to the last node data of a singly linked list
纯黑老白
博客等级 码龄18年 30粉丝 62原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值