1、 2)从键盘任意输入一个整数,在单链表中查询该数,如果单链表中已经存在这个数,就调用删除函数,删除该元素所在结点,并将单链表在删除前后的数据元素依次输出到屏幕上;(search 返回重复的位置,然后删除(同实验一) 如果单链表中不存在这个数,就调用插入函数,将这个数插入到单链表尾,并将单链表在插入前后的数据元素依次输出到屏幕上。(同实验一,直接加在链表末尾)3)判断插入元素与表内元素的大小,如temp-dataxlink-data,则插入temp后2_31)删除单链表中全部的负数(逐个判断是不是负数,并且返回负数所在位置,删除过春哥同实验一)2)创建一个双向链表,按照冒泡排序的思路对这个双向链
2、表进行排序,打印排序结果。(从一开始逐个比较,将比第一位大的与第一位交换位置,一直比较到最后一位然后开始对于第二位重复比较)二、程序代码 2_2#includemalloc.hstdlib.htypedef struct Node int data; struct Node *link;node;typedef struct List node *head; node *tail; int length;list;void creat_list(list *table) int x,i; node *temp; table-head=NULL;tail=NULL;length=0; x=1;s
3、canf(%d,&x); for(i=0;x!=0;i+) fflush(stdin); printf(n); temp=(node*)malloc(sizeof(node); temp-data=x;link=NULL;link=table-head; table-head=temp;length+; node * create_node(int new_node) node * temp; temp = (node*)malloc(sizeof(node); temp-data = new_node;link = NULL; return temp;void get(list *table
4、,int n) int i,loc=table-length+1; node *newnode; temp=table- newnode=create_node(n); for(i=2;ilink; newnode-link = temp-link = newnode;void show_list(list *table) printf(链表为: for(i=1;i length; x=temp-data;%d ,x);void delete_node(list *table,int n) int i; node *temp,*t; if(n=1) if(n2&nlength) temp=ta
5、ble- for(i=2;n; t=temp-link=t- if(n=table- for(i=2; temp=temp- if(n=2) t=temp-length-;void search(list *table,int x,int a2) int i=0,j=0;=table- if(x=temp-data) a1=i; j+; if(j=0) a0=0; a1=0; else a0=1;void main() list table; int m,a2; creat_list(&table); show_list(&n输入一个整数n scanf(m); search(&table,m,a); if(a0=1) delete_node(&table,a1);show_list(& elseget(&table,m);2_2(3) int i,m=0; if(nlink=temp; temp=newnode; else for(i=1;m=0; if(i m=1; else if(i=table- temp-link=newnode; m=1;2_3(1)head
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1