You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
1.1 KiB
73 lines
1.1 KiB
#include <iostream>
|
|
#include <stdlib.h>
|
|
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
|
|
|
|
typedef struct node
|
|
{
|
|
int data;
|
|
struct node *next;
|
|
}link;
|
|
|
|
link* a(){
|
|
link* p=(link*)malloc(sizeof(link));
|
|
p->next=NULL;
|
|
return p;
|
|
}
|
|
|
|
link* b(link* p){
|
|
link *temp = p;
|
|
link *c=a();
|
|
while(temp->next){
|
|
link *temp = p;
|
|
while(temp){
|
|
temp=temp->next;
|
|
}
|
|
int m = temp->data;
|
|
initlink(c,m);
|
|
}
|
|
return c;
|
|
}
|
|
|
|
void initlink(link* p,int n){
|
|
link * temp=p;
|
|
link *a=(link*)malloc(sizeof(link));
|
|
a->data=n;
|
|
a->next=NULL;
|
|
temp->next=a;
|
|
temp=temp->next;
|
|
}
|
|
|
|
void display(link* p){
|
|
link* temp = p;
|
|
while(temp->next){
|
|
temp=temp->next;
|
|
printf("%d",temp->data);
|
|
}
|
|
}
|
|
|
|
void ListInsert(link* p,int i,int e){
|
|
link* temp = p;
|
|
int j=0;
|
|
while(temp&&(j<i-1)){
|
|
temp=temp->next;++j;
|
|
}
|
|
if(!temp||j>j-1) return;
|
|
link *a=(link*)malloc(sizeof(link));
|
|
a->data=e;
|
|
a->next=temp->next;
|
|
temp->next=a;
|
|
return;
|
|
}
|
|
|
|
int main(int argc, char *argv[]) {
|
|
link *p=a();
|
|
int in;
|
|
for(int i=1;i<4;i++){
|
|
scanf("%d",&in);
|
|
initlink(p,in);
|
|
}
|
|
display(p)
|
|
p = b(b);
|
|
display(p)
|
|
return 0;
|
|
} |