qq_21890183 于 2016.03.28 16:38 提问

3个回答

lx624909677      2016.03.28 16:46

`````` #include<iostream>
using namespace std;
const int N=6;
typedef int DataType;//类型定义
typedef struct node{ //单链表
DataType data;
struct node* next;
/****由数组创建单链表****/
{
for(int i=N-1;i>=1;i--)
{
p->data=a[i];
}
}
/****输出单链表****/
{
else
{
while(p!=NULL)
{
cout<<p->data<<" ";
p=p->next;
}
cout<<endl;
}
}
{
if( (NULL==pCur)||(NULL==pCur->next) )
{
}
else
{
pNext->next=pCur;            //将后继结点指向当前结点。
pCur->next=NULL;
}
}
int main()
{
int a[N]={1,2,3,4,5,6};
PrintList(list);
ReverseList(pTemp,list);
PrintList(list);
return 0;
}
``````
caozhy      2016.03.28 16:43
`````` #include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct node{
int data;
struct node *next;
}NODE;

}else{
//头插法
}
}

//利用递归反转链表
NODE* reverse(NODE *first,NODE *second){
if(second==NULL)
return first;
NODE *third=second->next;
second->next=first;
return reverse(second,third);
}

int main(int argc,char *argv[]){
fprintf(stdout,"Input elements by order.Input negative to exit.\n");
int ele=0;
//根据用户的输入头插法建立单向链表
while(1){
scanf("%d",&ele);
if(ele<0)
break;
NODE *node=(NODE*)malloc(sizeof(NODE));
memset(node,0x00,sizeof(NODE));
node->data=ele;
node->next=NULL;
}
while(curr!=NULL){
printf("%d  ",curr->data);
curr=curr->next;
}
printf("\n");
while(curr!=NULL){
printf("%d  ",curr->data);
curr=curr->next;
}
printf("\n");
}
return 0;
}
``````
u014532650   2016.03.28 16:44

#include

using namespace std;

const int N=6;

typedef int DataType;//类型定义

typedef struct node{ //单链表

DataType data;

struct node* next;

/****由数组创建单链表****/

{

for(int i=N-1;i>=1;i--)

{

p->data=a[i];

}

}

/****输出单链表****/

{

{
while(p!=NULL)
{
coutdata<<" ";

p=p->next;

}

cout< }
}
{
if( (NULL==pCur)||(NULL==pCur->next) )

{

}

else

{

pNext->next=pCur; //将后继结点指向当前结点。

pCur->next=NULL;

}

}

int main()

{

int a[N]={1,2,3,4,5,6};

PrintList(list);