实现一个单链表的抽象数据类型,并将单链表就地逆置

来源:百度知道 编辑:UC知道 时间:2024/05/27 17:24:12
数据的上机作业,我不会啊,用C语言写,哪位大哥帮帮忙,我以后再也不抄作业了,明天就要,谢谢了!!!

//链表,实现功能初始化指定长度的链表,插入,删除,遍历,就地排序的功能,就地逆置
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
typedef struct LNode{
int data;
struct LNode *next;
}LNode,*LinkList;

LinkList CreatLinkList(LinkList head,int num){
LinkList s;
int i;
head=(LinkList)malloc(sizeof(LNode));
head->next=NULL;
for(i=0;i<num;i++){
s=(LinkList)malloc(sizeof(LNode));
printf("input the data:\n");
scanf("%d",&s->data);
s->next=head->next;
head->next=s;
}
printf("successfully create a LinkList with the length of:%d\n",num);
return head;
}

void InsertElem(LinkList head,int x,int location){
int k;
LinkList s,tmp;
s=head;k=0;
while(s->next!=NULL && k<location-1){//2.4.7.9. 3
s=s->next;
k++;
}
if(k!=location-1){
pr