zoukankan      html  css  js  c++  java
  • [置顶] 数据结构之 单链表的实现与操作

    // 链表.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); }

  • 相关阅读:
    Hibernate 基于外键的双向一对一关联映射
    Hibernate 基于外键的单项一对一关联映射
    Hibernate inverse
    Hibernate cascade
    Hibernate 双向一对多的关联映射
    Hibernate 单项一对多的关联映射
    (转)关闭iptables和SELinux
    linux下大于2T的硬盘格式化方法
    lsusb命令
    CentOS最小化安装后启用无线连接网络
  • 原文地址:https://www.cnblogs.com/zhujunxxxxx/p/3344864.html
Copyright © 2011-2022 走看看