双链表
来源:互联网 发布:网络拓扑图制作软件 编辑:程序博客网 时间:2024/04/27 13:33
//============================================================================
// Name : C++Study.cpp
// Author : pan
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
#include "Graph.h"
#include <stdio.h>
#include <vector>
#include <cstring>
#include <vector>
#include<stdlib.h>
#include<assert.h>
using namespace std;
struct Node {
char data;
Node* prior;
Node* next;
};
Node* createList(char a[], int n) {
Node* head = new Node;
Node* p = head;
for (int i = 0; i < n; i++) {
Node* node = new Node;
node->data = a[i];
Node* p2 = p;
p->next = node;
node->prior = p2;
p = p->next;
}
p->next = NULL;
return head;
}
void showList(Node* head) {
Node* p = head->next;
while (p != NULL) {
cout << p->data;
p = p->next;
}
cout << endl;
}
void delElem(Node* head, int pos) {
Node* p = head;
int i = 0;
while (p != NULL) {
if (i == pos) {
Node* node = p->next;
p->next = node->next;
delete node;
p->next->prior = p;
return;
}
i++;
p = p->next;
}
}
int main() {
char a[] = { 'a', 'b', 'c', 'd' };
Node* head = createList(a, 4);
//delElem(head,1);
showList(head);
/*insert(head, 1, 'g');
del(head,2);
showList(head);
myfree(head);*/
return 0;
}
// Name : C++Study.cpp
// Author : pan
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
#include "Graph.h"
#include <stdio.h>
#include <vector>
#include <cstring>
#include <vector>
#include<stdlib.h>
#include<assert.h>
using namespace std;
struct Node {
char data;
Node* prior;
Node* next;
};
Node* createList(char a[], int n) {
Node* head = new Node;
Node* p = head;
for (int i = 0; i < n; i++) {
Node* node = new Node;
node->data = a[i];
Node* p2 = p;
p->next = node;
node->prior = p2;
p = p->next;
}
p->next = NULL;
return head;
}
void showList(Node* head) {
Node* p = head->next;
while (p != NULL) {
cout << p->data;
p = p->next;
}
cout << endl;
}
void delElem(Node* head, int pos) {
Node* p = head;
int i = 0;
while (p != NULL) {
if (i == pos) {
Node* node = p->next;
p->next = node->next;
delete node;
p->next->prior = p;
return;
}
i++;
p = p->next;
}
}
int main() {
char a[] = { 'a', 'b', 'c', 'd' };
Node* head = createList(a, 4);
//delElem(head,1);
showList(head);
/*insert(head, 1, 'g');
del(head,2);
showList(head);
myfree(head);*/
return 0;
}
0 0
- 双链表
- 双链表
- 双链表
- 双链表
- 双链表
- 双链表
- 双链表
- 双链表
- 双链表
- 双链表
- 双链表
- 双链表
- 双链表
- 双链表
- 双链表
- 双链表
- 双链表
- 双链表
- 83. Remove Duplicates from Sorted List
- crond(cron) 和 crontab
- 黑马程序员---面向对象
- 使用JQueryMobile时js文件报错,保存时总弹错误消息框
- 好好把握现在,没有什么是理所当然的
- 双链表
- ARC简介以及工程中ARC与非ARC的混合
- 机器学习实战——第十一/十二章:关联规则挖掘Apriori算法和FP-growth算法
- 【麦可网】Cocos2d-X跨平台游戏开发学习笔记---第二十一课:Cocos2D-X网格特效1-3
- 机器视觉网站资料
- malloc原理和内存碎片
- static总结
- leetcode[228]:Summary Ranges
- AS之NDK配置