#include <iostream>
using namespace std;
struct Node{
int dato;
Node *link;
};
Node *fin=NULL, *inicio=NULL;
void meter(int num){
Node *t=NULL, *t2;
t2=inicio;
t=new Node;
t->dato=num;
t->link=NULL;
if(inicio==NULL||num<inicio->dato){
if(fin==NULL)
fin=inicio=t;
else{
t->link=inicio;
inicio=t;
}
}
else{
if(num>fin->dato){
t->link=fin;
fin=t;
}
else{
while(t->dato<t2->dato){
t2=t2->link;
}
t->link=t2->link;
t2->link=t;
}
}
}
void mostrar(){
Node *t;
t=inicio;
do{
cout<<t->dato<<endl;
t=t->link;
}while(t!=NULL);
}
void del(){
}
int main(){
int num;
while(true){
cout<<"Ingrese un numero 0 para salir ";
cin>>num;
if(num==0)
break;
meter(num);
}
mostrar();
system("pause");
return 0;
}
Thank You

New Topic/Question
Reply




MultiQuote






|