parent
30c45b4fbb
commit
f1877fd909
@ -1,2 +1,71 @@
|
||||
# c
|
||||
#include <iostream>
|
||||
|
||||
/* 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;
|
||||
}node,*link;
|
||||
|
||||
link* a(){
|
||||
link *p=(link*)malloc(sizeof(link));
|
||||
p->netx=NULL;
|
||||
return p;
|
||||
}
|
||||
|
||||
link* b(link* p){
|
||||
link *temp = p;
|
||||
link *c=a();
|
||||
while(temp->next){
|
||||
link *temp = p;
|
||||
while(temp)){
|
||||
temp=temp->next;
|
||||
}
|
||||
initlink(c,temp->data);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
Loading…
Reference in new issue