c++单向链表

自己照着视频仿照着写的,但是运行却不行啊,比较迷茫

#include<iostream>
using namespace std;
typedef struct MyStruct
{
 int data;
 MyStruct* next;
}L,*LP;
LP CreateList()
{
 LP List = new L;
 if (List == 0)
 {
  cout << "链表初始化失败" << endl;
  system("pause");
  exit(0);
 }
 List->next =0;
 return List;
}
LP CreateNode(int data)
{
 LP Node = new L;
 Node->data = data;
 Node->next = 0;
 return Node;
}
//头插法
void InsertListHeadNode(LP List, int data)
{
 LP NewNode = CreateNode(data);
 NewNode->next = List->next;
 List->next = NewNode->next;
}
bool IsEmptyList(LP List)
{
 if (List == 0)
 {
  return 1;
 }
 return 0;
}
void PrintList(LP List)
{
 LP PList = List->next;
 while (PList != 0)
 {
  cout << PList <<" \t"<< endl;
  PList = PList->next;
 }
}
int main()
{
 LP List = CreateList( );
 IsEmptyList(List);
 CreateNode(5);
 InsertListHeadNode(List,4 );
 InsertListHeadNode(List, 3);
 InsertListHeadNode(List, 6);
 InsertListHeadNode(List, 8);
 InsertListHeadNode(List, 10);
 PrintList(List);
 system("pause");
 return 0;
}
希望有大佬看到帮忙看看

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值