简单 单链表的增删改查 c++描述
简单 单链表的增删改查 c++描述
class node{
public :
int data;
node * next;
};
#include "node.h"
using namespace std;
class stack{
public :
node * head;
stack(){
head=NULL;
}
void add(int data);
void del(int data);
void print();
void edit(int olddata,int newdata);
node * getnode(int data);
};
#include<iostream>
#include "stack.h"
using namespace std;
void stack::add(int data){//添加节点
if(head==NULL){
head=new node();
head->data=data;
head->next=NULL;
}else{
node * n=head;
while(n->next!=NULL){
n=n->next;
}
node * n_=new node();
n_->data=data;
n_->next=NULL;
n->next=n_;
}
}
void stack::print(){//打印节点
node * n=head;
while(n!=NULL){
cout<<n->data<<" ";
n=n->next;
}
}
void stack::del(int data){//删除节点
if(head!=NULL){
if(head->data==data){
head=head->next;
return;
}
}else{
return;
}
node * n=head;
while(n->next!=NULL){
if(n->next->data==data){
node * n_=n->next;
n_=NULL;
n->next=n->next->next;
return;
}
n=n->next;
}
}
void stack::edit(int olddata,int newdata){//更改节点data
node * n=head;
while(n!=NULL){
if(n->data==olddata){
n->data=newdata;
return;
}
n=n->next;
}
}
node* stack::getnode(int data){//获取节点
node * n=head;
while(n!=NULL){
if(n->data==data){
return n;
}
n=n->next;
}
return NULL;
}
void main(){
stack * s=new stack();
s->add(1);
s->add(2);
s->add(3);
s->add(4);
s->del(1);
s->edit(3,6);
s->print();
cout<<endl;
cout<<s->getnode(6)->data<<endl;
}
评论区
请写下您的评论...
猜你喜欢
blog
简单 双向链表得增删改查 c++描述
数据结构与算法
2458
简单双向链表得增删改查c++描述classnode{public:intdata;node*next;node*prev;};#include"node.h"classrelink
blog
链式栈的出栈入栈操作c++描述
数据结构与算法
3171
链式栈的出栈入栈操作c++描述基于双向链表//节点classnode{public:intdata;node*next;node*prev;};//双向链表#include"node.h
ofc
删除链表中的节点
official
1020
leetcode第237题(简单)原链接:https://leetcode-cn.com/problems/delete-node-in-a-linked-list/submissions/问题描述
blog
shell简单入门
linux系统
1831
编写shell脚本有两点要求1.脚本一般都是以#!/bin/bash开头(告诉我们系统我们这个脚本使用bash进行解释,不加也可以运行)2.给予脚本可执行的权限3.执行shell脚本的方式1)./脚本名2)sh+脚本名(此种方式不需要有可执行权限,但是不建议使用)
blog
一个简单的springboot
框架
2484
创建一个Maven项目,2.修改jdk版本(因为这里使用的springboot是1.5,在2.0一下springboot推荐使用1.7)!--修改jdk版本springboot2.0之前推荐使用
数据结构与算法
4585
递归实现合并两递增链表-合并后保持递增序列java描述数据结构:单链表算法:递归链表节点packageclub.test;/****链表节点*@authorjiajia
框架
2821
1.项目结构2.pom文件依赖?xmlversion="1.0"encoding="UTF-8"?projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.
official
1163
,等待客户端发送消息。先看一个bio最简单的例子:publicstaticvoidmain1(String[]args)throwsIOException{
//绑定端口
ServerSocketserv
最新发表
归档
2018-11
12
2018-12
33
2019-01
28
2019-02
28
2019-03
32
2019-04
27
2019-05
33
2019-06
6
2019-07
12
2019-08
12
2019-09
21
2019-10
8
2019-11
15
2019-12
25
2020-01
9
2020-02
5
2020-03
16
2020-04
4
2020-06
1
2020-07
7
2020-08
13
2020-09
9
2020-10
5
2020-12
3
2021-01
1
2021-02
5
2021-03
7
2021-04
4
2021-05
4
2021-06
1
2021-07
7
2021-08
2
2021-09
8
2021-10
9
2021-11
16
2021-12
14
2022-01
7
2022-05
1
2022-08
3
2022-09
2
2022-10
2
2022-12
5
2023-01
3
2023-02
1
2023-03
4
2023-04
2
2023-06
3
2023-07
4
2023-08
1
2023-10
1
2024-02
1
2024-03
1
2024-04
1
2024-08
1
标签
算法基础
linux
前端
c++
数据结构
框架
数据库
计算机基础
储备知识
java基础
ASM
其他
深入理解java虚拟机
nginx
git
消息中间件
搜索
maven
redis
docker
dubbo
vue
导入导出
软件使用
idea插件
协议
无聊的知识
jenkins
springboot
mqtt协议
keepalived
minio
mysql
ensp
网络基础
xxl-job
rabbitmq
haproxy
srs
音视频
webrtc
javascript
加密算法
目录
没有一个冬天不可逾越,没有一个春天不会来临。最慢的步伐不是跬步,而是徘徊,最快的脚步不是冲刺,而是坚持。