Dev - C++ - pasar este código de "C++" a C

 
Vista:
Imágen de perfil de Lisardo
Val: 14
Ha mantenido su posición en Dev - C++ (en relación al último mes)
Gráfica de Dev - C++

pasar este código de "C++" a C

Publicado por Lisardo (1 intervención) el 07/03/2019 04:40:43
Buenas noches, necesito por favor pasar este código de "C++" a C, muchas gracias en lo que me puedan ayudar

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include <iostream>
using namespace std;
 
struct nodo
{
    int nro;
    struct nodo *sgte;
};
 
struct cola
{
    nodo *delante;
    nodo *atras  ;
};
 
void encolar( struct cola &q, int valor )
{
     struct nodo *aux = new(struct nodo);
 
     aux->nro = valor;
     aux->sgte = NULL;
 
     if( q.delante == NULL)
         q.delante = aux;
     else
         (q.atras)->sgte = aux;
 
     q.atras = aux;
 
}
 
int desencolar( struct cola &q )
{
     int num ;
     struct nodo *aux ;
 
     aux = q.delante;
     num = aux->nro;
     q.delante = (q.delante)->sgte;
     delete(aux);
 
     return num;
}
 
void muestraCola( struct cola q )
{
     struct nodo *aux;
 
     aux = q.delante;
 
     while( aux != NULL )
     {
            cout<<"   "<< aux->nro ;
            aux = aux->sgte;
     }
}
 
void vaciaCola( struct cola &q)
{
     struct nodo *aux;
 
     while( q.delante != NULL)
     {
            aux = q.delante;
            q.delante = aux->sgte;
            delete(aux);
     }
     q.delante = NULL;
     q.atras   = NULL;
 
}
 
void menu()
{
    cout<<"\n\t IMPLEMENTACION DE COLAS EN C++\n\n";
    cout<<" 1. ENCOLAR                               "<<endl;
    cout<<" 2. DESENCOLAR                            "<<endl;
    cout<<" 3. MOSTRAR COLA                          "<<endl;
    cout<<" 4. VACIAR COLA                           "<<endl;
    cout<<" 5. SALIR                                 "<<endl;
 
    cout<<"\n INGRESE OPCION: ";
}
 
  int main()
{
    struct cola q;
 
    q.delante = NULL;
    q.atras   = NULL;
 
 
    int dato;
    int op;
    int x ;
 
    system("color 0b");
 
    do
    {
        menu();  cin>> op;
 
        switch(op)
        {
            case 1:
 
                 cout<< "\n NUMERO A ENCOLAR: "; cin>> dato;
                 encolar( q, dato );
                 cout<<"\n\n\t\tNumero " << dato << " encolado...\n\n";
            break;
 
            case 2:
 
                 x = desencolar( q );
                 cout<<"\n\n\t\tNumero "<< x <<" desencolado...\n\n";
            break;
 
            case 3:
 
                 cout << "\n\n MOSTRANDO COLA\n\n";
                 if(q.delante!=NULL) muestraCola( q );
                 else   cout<<"\n\n\tCola vacia...!"<<endl;
            break;
 
            case 4:
 
                 vaciaCola( q );
                 cout<<"\n\n\t\tHecho...\n\n";
            break;
 
         }
 
        cout<<endl<<endl;
        system("pause");  system("cls");
 
    }while(op!=5);
 
 
    return 0;
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Alfil
Val: 4.344
Oro
Ha mantenido su posición en Dev - C++ (en relación al último mes)
Gráfica de Dev - C++

pasar este código de "C++" a C

Publicado por Alfil (1444 intervenciones) el 08/03/2019 19:42:28
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include <stdio.h>
#include <stdlib.h>
 
typedef struct nodo{
    int nro;
    struct nodo *sgte;
};
 
typedef struct cola{
    struct nodo *delante;
    struct nodo *atras ;
};
 
void encolar( struct cola *q, int valor ){
 
     struct nodo *aux = malloc( sizeof(struct nodo) );
     aux->nro = valor;
     aux->sgte = NULL;
 
     if( q->delante == NULL)
         q->delante = aux;
     else
         (q->atras)->sgte = aux;
 
     q->atras = aux;
}
 
int desencolar( struct cola *q ){
 
     int num ;
     struct nodo *aux ;
 
     aux = q->delante;
     num = aux->nro;
     q->delante = (q->delante)->sgte;
 
     free(aux);
 
     return num;
}
 
void muestraCola( struct cola q ){
 
     struct nodo *aux;
 
     aux = q.delante;
 
     while( aux != NULL ){
        printf( "    %d", aux->nro );
        aux = aux->sgte;
     }
}
 
void vaciaCola( struct cola *q){
 
     struct nodo *aux;
 
     while( q->delante != NULL){
            aux = q->delante;
            q->delante = aux->sgte;
 
            free(aux);
     }
     q->delante = NULL;
     q->atras   = NULL;
}
 
void menu(){
 
    printf( "\n\t IMPLEMENTACION DE COLAS EN C++\n\n" );
    printf( " 1. ENCOLAR                               \n" );
    printf( " 2. DESENCOLAR                            \n" );
    printf( " 3. MOSTRAR COLA                          \n" );
    printf( " 4. VACIAR COLA                           \n" );
    printf( " 5. SALIR                                 \n" );
    printf( "\n INGRESE OPCION: " );
 
}
 
  int main(){
 
    struct cola q;
    q.delante = NULL;
    q.atras   = NULL;
    int dato;
    int op;
    int x ;
    system("color 0b");
 
    do{
        menu();  scanf( "%d", &op );
 
        switch(op){
 
            case 1:
                printf( "\n NUMERO A ENCOLAR: " ); scanf( "%d", &dato );
                encolar( &q, dato );
                printf( "\n\n\t\tNumero %d encolado...\n\n", dato );
                break;
 
            case 2:
                 x = desencolar( &q );
                 printf( "\n\n\t\tNumero %d desencolado...\n\n", x );
                break;
 
            case 3:
                 printf( "\n\n MOSTRANDO COLA\n\n" );
                 if(q.delante!=NULL) muestraCola( q );
                 else  printf( "\n\n\tCola vacia...!\n" );
                break;
 
            case 4:
                 vaciaCola( &q );
                 printf( "\n\n\t\tHecho...\n\n" );
                break;
        }
        printf( "\n\n" );
        system("pause");  system("cls");
 
    }while( op != 5);
 
    return 0;
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar