采用VC开发环境创建链表

来源:百度知道 编辑:UC知道 时间:2024/05/24 01:41:19
1创建一个单向列表
2在链表中前向插入一个单元
3在链表中后向插入一个单元
4删除一个单元

小弟水平有限,特请教高手相助,请帮忙写出程序,谢谢!

/*=============================
1创建一个单向列表
2在链表中前向插入一个单元
3在链表中后向插入一个单元
4删除一个单元

首先创建链表,当输入-1时创建链表结束
由于链表的数据域是整形,所以输入应该是
数字。
前插插入链表:需要输入插入位置和元素,
注意插入位置不能大于链表长度
删除链表:需要输入删除位置和元素
后插插入链表:需要输入插入位置和元素
注意插入位置不能大于链表长度
所有的输入数组都用空格隔开,每次执行完操作
之后都会输出当前链表的所有值。
===============================*/
#include<stdio.h>
#include<stdlib.h>

struct iNode{
int data;
struct iNode *next;
};

struct iNode *create()
{
struct iNode *hp =NULL;//head

struct iNode *tp =NULL;//tail

struct iNode *cp =NULL;//current

int data;
printf("the element of the LinkList, if input -1 creat finish:\n");
while(1)
{
scanf("%d",&data);
if(data <= 0)break;
cp =(struct iNode*)malloc(sizeof(struct iNode));
if(cp ==NULL)