双链表

来源:互联网 发布:网络拓扑图制作软件 编辑:程序博客网 时间: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;
}
0 0
原创粉丝点击