删除链表中指定位置的元素
来源:互联网 发布:麒麟linux 编辑:程序博客网 时间:2024/05/16 16:08
#include<stdio.h>
#include<iostream>
using namespace std;
typedef int Elemtype;
typedef struct node {
Elemtype data;
struct node* next;
};
node* Greatlist(int n) //创建链表
{
node*p, *r, *head = NULL;
r = (node*)malloc(sizeof(node));
int i;
Elemtype c;
for (i = 1; i <= n; i++)
{
cin >> c;
p = (node*)malloc(sizeof(node));
p->data = c;
p->next = NULL;
if (head == NULL)
{
r=head= p;
}
else
{
r->next = p;
r = p;
}
}
return head;
}
int Linklen(node*head) //返回链表长度,本题中用不到这个函数
{
int count = 0;
node* p = head;
while (p!=NULL)
{
count++;
p=p->next;
}
return count;
}
node* getPtr(node* head, int pos) //得到指定位置的链表元素的指针
{
node* p = head;
int i;
for (i = 1; i < pos; i++)
{
p = p->next;
}
return p;
}
int main()
{
node*l;
cout << "input 10 interger:" << endl;
l = Greatlist(10);
cout << "the length is:" << Linklen(l) << endl;
node*p, *q;
p = getPtr(l, 4);
q = p->next;
p->next = q->next;
free(q);
cout << "the linklist after deleting the fifth node :" << endl;
p = l;
while (p)
{
cout << p->data << " ";
p = p->next;
}
return 0;
}
- 删除链表中指定位置的元素
- 删除链表中指定的元素
- 将数组中指定位置的元素删除
- 删除一个数组中指定位置的元素
- 删除链表中指定元素
- 删除链表中指定的所有元素
- 删除字符串中指定位置的字符
- 删除字符串中指定位置的字符
- 删除vector中指定的元素
- 删除数组中指定的元素
- 如何删除数组中指定的元素
- 删除map容器中指定的元素
- Leetcode019--删除数组中指定的元素
- js删除json中指定的元素
- Remove Linked List Elements 删除链表中指定元素
- 在数组中指定位置添加和删除元素
- 删除List中指定元素
- 删除数值中指定元素
- Linux(妙算)串口通信
- web服务器搭建之ngrok篇
- LeetCode——026
- 分享一个完整的Mybatis分页解决方案
- 解决sui的Form表单验证回调问题
- 删除链表中指定位置的元素
- Android Bundle详解
- opencv实用小技巧
- cesium学习1--环境搭建和配置
- 9连连看
- Xcode 静态分析与内存泄漏检查
- Spring3 整合MyBatis3 配置多数据源 动态选择SqlSessionFactory
- proteus仿真 BUZZER 不响
- 华为P9遭疯抢,首发3分钟售罄;苹果汽车概念图遭权威杂志曝光引热议;中科大机器人太逼真