
Ayuda para pasar programa en c a java
Publicado por Alan (2 intervenciones) el 20/10/2017 01:52:53
hola este es el codigo c
en java estoy intentando algo así pero no logro compilar:
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
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "stack.h"
void insert(NODO **head, int argc, char **argv);
void move(NODO **LEFT, NODO **RIGHT);
void display_estrellas(NODO **LEFT, NODO **RIGHT);
int main (int argc, char **argv)
{
NODO *A = NULL;
NODO *B = NULL;
NODO *C = NULL;
insert(&A, argc, argv);
move(&A,&B);
display_estrellas(&B,&A);
display_estrellas(&A,&B);
}
void display(int n)
{
int i;
for (i = 0; i < n -1 ; i++)
{
printf(" ";
}
printf("*n";
}
void move(NODO **LEFT, NODO **RIGHT)
{
int a = 0;
while(a != -1){
a = pop(LEFT);
if (a != -1)
{
push(RIGHT,a);
}
}
}
void insert(NODO **head, int argc, char **argv)
{
int i;
for (i = 0; i < argc; ++i)
{
if (isdigit(*argv))
{
push(head, atoi(argv));
}
}
}
void display_estrellas(NODO **LEFT, NODO **RIGHT)
{
int a = 0;
while(a != -1){
a = pop(LEFT);
if (a != -1)
{
display(a);
push(RIGHT,a);
}
}
}
en java estoy intentando algo así pero no logro compilar:
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
import java.util.*;
import java.lang.*;
public class estrellas {
public static void main(String args[]) {
Queue<Integer> q = new LinkedList<Integer>();
Stack st = new Stack();
insert(q, args);
//q.insert(args);
display_estrellas(q, st);
moveq(q, st);
movest(st, q);
display_estrellas(q, st);
}
public static void display(int n) {
int i;
for (i = 0; i < n - 1; i++) {
System.out.print(" ";
}
System.out.println("*";
}
public static void moveq(Queue<Integer> q, Stack st) {
int a = 0;
while (a != -1) {
// a = q.pop(a);
// q.add(a);
// q.remove(a);
a = q.remove(); //aqui es donde pienso que hay error
if (a != -1) {
q.add(a); //aqui es donde pienso que hay error
}
}
}
public static void movest(Stack st, Queue<Integer> q) {
int a = 0;
while (a != -1) {
//q.remove(a);
a = q.remove(); //aqui es donde pienso que hay error
if (a != -1) {
st.push(a); //aqui es donde pienso que hay error
//q.add(a);
}
}
}
public static void insert(Queue<Integer> q, String[] args) {
char c;
String cadena;
int i;
cadena = Arrays.toString(args);
for (i = 0; i < cadena.length(); ++i) {
c = cadena.charAt(i);
if (Character.isDigit(c) == true) {
q.add(Character.getNumericValue(c));
}
}
}
public static void display_estrellas(Queue<Integer> q, Stack st) {
int a = 0;
while (a != -1) {
a = q.remove(); //aqui es donde pienso que hay error
if (a != -1) {
display(a);
q.add(a); //aqui es donde pienso que hay error
// st.add(a);
}
}
}
}
Valora esta pregunta


0