免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
第十二課 實驗二 循環(huán)鏈表實驗

本課主題: 實驗二 循環(huán)鏈表實驗

教學(xué)目的: 掌握單向鏈表的實現(xiàn)方法

教學(xué)重點: 單向鏈表的存儲表示及操作

教學(xué)難點: 單向鏈表的操作實現(xiàn)

授課內(nèi)容:

一、單向鏈表的存儲表示

C源程序

#include<stdio.h>#include<malloc.h>#include<conio.h>#define ERROR 0#define OK 1#define EQUAL 1#define OVERFLOW -1#define LIST_INIT_SIZE 100#define LISTINCREMENT 10struct STU{  char name[20];  char stuno[10];  int age;  int score;}stu[50];typedef struct STU ElemType;struct LNODE{  ElemType data;  struct LNODE *next;};typedef struct LNODE LNode;typedef struct LNODE *LinkList;int init(LinkList *L){  *L=(LNode *)malloc(sizeof(LNode));  if(!L)   exit(ERROR);  (*L)->next=NULL;  return OK;}/*init */int ListLength(LinkList L){  int j=0;  while (L->next)    {      L=L->next;      j++;    }  return j;}int GetElem(LinkList L,int i,ElemType *e){  LinkList p; int j;  p=L->next;j=1;  while(p&&j<i){    p=p->next;++j;  }  if(!p||j>1)  return ERROR;  *e=p->data;  return OK;}int EqualList(ElemType *e1,ElemType *e2){  if (strcmp(e1->name,e2->name)==0)    return 1;  else    return 0;}int Less_EqualList(ElemType *e1,ElemType *e2){  if (strcmp(e1->name,e2->name)<=0)    return 1;  else    return 0;}int LocateElem(LinkList La,ElemType e,int type){  int i;  LinkList p;  p=La;  switch (type)    {      case EQUAL:	  while(p->next)	    {	      p=p->next;	      if(EqualList(&p->data,&e))	       return 1;	    }	  return 0;	break;      default:	break;    }  return 0;}void MergeList(LinkList La,LinkList Lb,LinkList *Lc){  LinkList pa,pb,pc;  pa=La->next;pb=Lb->next;  *Lc=pc=La;  while(pa && pb)    {      if(Less_EqualList(&pa->data,&pb->data))	{	  pc->next=pa;pc=pa;pa=pa->next;	}      else	{	  pc->next=pb;pc=pb;pb=pb->next;	}    }  pc->next=pa?pa:pb;  free(Lb);}int printlist(LinkList L){  int i;  LinkList p;  p=L;  printf("name       stuno        age     score\n");  while(p->next)    {      p=p->next;      printf("%-10s %s\t%d\t%d\n",  p->data.name,  p->data.stuno,	  p->data.age,  p->data.score);    }  printf("\n");}int ListInsert(LinkList L,int i,ElemType e){  LinkList p,s;  int j;  p=L;j=0;  while(p&&j<i-1)    {      p=p->next;      ++j;    }  if(!p||j>i-1) return ERROR;  s=(LinkList)malloc(sizeof(LNode));  s->data=e;  s->next=p->next;  p->next=s;  return OK;}/*ListInsert Before i */main(){  struct STU e;  LinkList La,Lb,Lc;  clrscr();  printf("\n\n-------------------List Demo is running...----------------\n\n");  printf("First is InsertList function.\n");  init(&La);  strcpy(e.name,"stu1");  strcpy(e.stuno,"100001");  e.age=80;  e.score=1000;  ListInsert(La,1,e);  strcpy(e.name,"stu3");  strcpy(e.stuno,"100002");  e.age=80;  e.score=1000;  ListInsert(La,2,e);  printlist(La);  getch();  strcpy(e.name,"stu5");  strcpy(e.stuno,"100003");  e.age=80;  e.score=1000;  ListInsert(La,3,e);  printlist(La);  getch();  init(&Lb);  strcpy(e.name,"stu2");  strcpy(e.stuno,"100001");  e.age=80;  e.score=1000;  ListInsert(Lb,1,e);  strcpy(e.name,"stu4");  strcpy(e.stuno,"100002");  e.age=80;  e.score=1000;  ListInsert(Lb,2,e);  strcpy(e.name,"stu6");  strcpy(e.stuno,"100001");  e.age=80;  e.score=1000;  ListInsert(Lb,3,e);  printlist(Lb);  getch();  MergeList(La,Lb,&Lc);  printlist(Lc);  getch();  printf("\n\n\n\n\n\nWelcome to visit http://zmofun.heha.net !\n\n\n\n\n\n\n");}
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
用C語言實現(xiàn)單鏈表的各種操作
數(shù)據(jù)結(jié)構(gòu)實驗一
使用C語言實現(xiàn)線性表
1、鏈表的基本操作( 無頭結(jié)點)
數(shù)據(jù)結(jié)構(gòu)
單鏈表操作(自制)
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服