写个算法(c语言)

来源:百度知道 编辑:UC知道 时间:2024/07/01 00:57:41
对单链表实现就地逆置。

刚学数据结构,觉得这个链表好麻烦的。。。

/* 单链表就地逆置算法 */
void converse(NODEPTR L)
{
NODEPTR p,q;
p=L->next; q=p->next;
L->next=NULL;
while(p) /* 对于当前结点p,用头插法将结点p插入到头结点之后 */
{
p->next=L->next;
L->next=p;
p=q;
q=q->next;
}
}

买一送一吧:
-------------------------------
-------------------------------
/* 单链表就地逆置的C语言程序 */
#define NULL 0

/*定义单链表的数据类型 */
typedef struct node{
int data;
struct node * next;
}NODE,*NODEPTR;

/*创建单链表 */
NODEPTR createlink()
{
NODEPTR L,p,q;
int i,n,e;
L=(NODEPTR)malloc(sizeof(NODE));
L->next=NULL;
q=L;

printf("please input the length of the link list\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
p=(NODEPTR)malloc(sizeof(NODE));
printf("please enter the value of the list element\n&