C++ 链表操作
2004-08-17 16:27
369 查看
#include <iostream.h>
struct student
{
int num;
int score;
struct student *next;
};
int n;
struct student *CreateLink()
{
struct student *head;
struct student *p1=NULL;
struct student *p2=NULL;
int num = 1;
int score = 11;
n = 0;
p1 = new struct student();
p2 = p1;
if (p1 == NULL)
{
cout<<"/nCann't create it, try it again in a moment!/n";
return NULL;
}
else
{
head = NULL;
p1->num = num++;
p1->score = score++;
}
while(p1->num < 10)
{
n += 1;
if (n==1)
{
head = p1;
p2->next = NULL;
}
else
{
p2->next = p1;
}
p2 = p1;
p1 = new struct student();
p1->num = num++;
p1->score = score++;
}
p2->next = NULL;
delete(p1);
p1 = NULL;
return head;
}
void Print(struct student *head)
{
struct student *p;
p = head;
if(head != NULL)
{
do
{
cout<num<<'/t'<score<<'/t'<next<
struct student
{
int num;
int score;
struct student *next;
};
int n;
struct student *CreateLink()
{
struct student *head;
struct student *p1=NULL;
struct student *p2=NULL;
int num = 1;
int score = 11;
n = 0;
p1 = new struct student();
p2 = p1;
if (p1 == NULL)
{
cout<<"/nCann't create it, try it again in a moment!/n";
return NULL;
}
else
{
head = NULL;
p1->num = num++;
p1->score = score++;
}
while(p1->num < 10)
{
n += 1;
if (n==1)
{
head = p1;
p2->next = NULL;
}
else
{
p2->next = p1;
}
p2 = p1;
p1 = new struct student();
p1->num = num++;
p1->score = score++;
}
p2->next = NULL;
delete(p1);
p1 = NULL;
return head;
}
void Print(struct student *head)
{
struct student *p;
p = head;
if(head != NULL)
{
do
{
cout<num<<'/t'<score<<'/t'<next<
相关文章推荐
- [C++]数据结构:有序链表SortedChain的基本实现与操作
- C++的链表操作
- C++链表的创建与操作
- 单链表结点读取、插入、删除操作(基本操作)-C++
- 基于c++的单链表,双向链表操作以及环
- 单链表基础操作C++实现
- 使用C++链表来实现二叉树的存储和基本操作
- c++链表简易操作
- C/C++链表操作(面试)
- 数据结构_队列_用链表动态建立释放节点实现队列各种操作_C++实现
- c++分别用数组和链表实现栈的操作
- 【C++】实现双向链表的所有操作,包括逆置双链表(三种方法)
- c++实现链表的基本操作
- C++ 双链表的基本操作
- 【链表】C++链表操作大全:创建链表、遍历链表、删除链表结点、寻找环入口、链表加法、判断回文等
- 《C++第十四周实验报告2-1》---建立专门的链表类处理有关动态链表的操作
- (C++版)链表(一)——实现单向链表创建、插入、删除等相关操作
- c++链表的操作
- C++实现链表操作
- 数据结构--单向链表操作(C++版)