[置顶] 数据结构之 单链表的实现与操作

 
 

// 链表.cpp : 定义控制台应用程序的入口点。 //

#include "stdafx.h" #include "malloc.h" #define maxSize 10 //单链表节点定义 typedef struct LNode {  char data;  struct LNode *next; }LNode; //插入数据 在第locate个节点位置插入 void Listinsert(LNode *&L,int locate,int x) {  LNode *p,*s;  p=L;  int j=0;  while(p!=NULL&&j<locate-1)  {   p=p->next;   j++;  }  s=(LNode*)malloc(sizeof(LNode));  s->data=x;

 s->next=p->next;  p->next=s; } //删除节点 void ListDel(LNode *&L,int locate) {  LNode *p,*q;  int j=0;  p=L;  while(p->next!=NULL&&j<locate-1)  {   p=p->next;   j++;  }  q=p->next;  p->next=q->next;  free(q);

} void show(LNode *L) {  LNode *p=L->next;  while(p!=NULL)  {   printf("%d ",p->data);   p=p->next;  } } void CreatelistR(LNode *&L,int a[],int n) {  LNode *s,*r;  L=(LNode*)malloc(sizeof(LNode));  L->next=NULL;  r=L;  for(int i=0;i<n;i++)  {   s=(LNode*)malloc(sizeof(LNode));   s->data=a[i];   r->next=s;   r=s;  }  r->next=NULL; } int _tmain(int argc, _TCHAR* argv[]) {  LNode *L;  int a[]={2,4,5,7,8,20};  CreatelistR(L,a,6);  //ListDel(L,1);  Listinsert(L,1,-1);  Listinsert(L,1,-2);  Listinsert(L,1,-3);  Listinsert(L,1,-4);  Listinsert(L,1,-6);  Listinsert(L,1,-7);  show(L); }

转载于:https://www.cnblogs.com/zhujunxxxxx/p/3344864.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值