Kısa İki Java Kodunu C#' A Çevirir Misiniz ?
-
1. Kod:
class Queue { private int maxSize; private long[] queArray; private int front; private int rear; private int nItems; //-------------------------------------------------------------- public Queue(int s) // constructor { maxSize = s; queArray = new long[maxSize]; front = 0; rear = -1; nItems = 0; } //-------------------------------------------------------------- public void insert(long j) // put item at rear of queue { if(rear == maxSize-1) // deal with wraparound rear = -1; queArray[++rear] = j; // increment rear and insert nItems++; // one more item } //-------------------------------------------------------------- public long remove() // take item from front of queue { long temp = queArray[front++]; // get value and incr front if(front == maxSize) // deal with wraparound front = 0; nItems--; // one less item return temp; } //-------------------------------------------------------------- public long peekFront() // peek at front of queue { 138 CHAPTER 4 Stacks and Queues 05 0672324539 CH04 10/10/02 9:09 AM Page 138return queArray[front]; } //-------------------------------------------------------------- public boolean isEmpty() // true if queue is empty { return (nItems==0); } //-------------------------------------------------------------- public boolean isFull() // true if queue is full { return (nItems==maxSize); } //-------------------------------------------------------------- public int size() // number of items in queue { return nItems; } //-------------------------------------------------------------- } // end class Queue //////////////////////////////////////////////////////////////// class QueueApp { public static void main(String[] args) { Queue theQueue = new Queue(5); // queue holds 5 items theQueue.insert(10); // insert 4 items theQueue.insert(20); theQueue.insert(30); theQueue.insert(40); theQueue.remove(); // remove 3 items theQueue.remove(); // (10, 20, 30) theQueue.remove(); theQueue.insert(50); // insert 4 more items theQueue.insert(60); // (wraps around) theQueue.insert(70); theQueue.insert(80); while( !theQueue.isEmpty() ) // remove and display { // all items Queues 139 LISTING 4.4 Continued 05 0672324539 CH04 10/10/02 9:09 AM Page 139long n = theQueue.remove(); // (40, 50, 60, 70, 80) System.out.print(n); System.out.print(“ “); } System.out.println(“”); } // end main() } // end class QueueApp2. Kod
class StackX { private int maxSize; // size of stack array private long[] stackArray; private int top; // top of stack //-------------------------------------------------------------- public StackX(int s) // constructor { maxSize = s; // set array size stackArray = new long[maxSize]; // create array top = -1; // no items yet } //-------------------------------------------------------------- public void push(long j) // put item on top of stack { stackArray[++top] = j; // increment top, insert item } 120 CHAPTER 4 Stacks and Queues 05 0672324539 CH04 10/10/02 9:09 AM Page 120//-------------------------------------------------------------- public long pop() // take item from top of stack { return stackArray[top--]; // access item, decrement top } //-------------------------------------------------------------- public long peek() // peek at top of stack { return stackArray[top]; } //-------------------------------------------------------------- public boolean isEmpty() // true if stack is empty { return (top == -1); } //-------------------------------------------------------------- public boolean isFull() // true if stack is full { return (top == maxSize-1); } //-------------------------------------------------------------- } // end class StackX //////////////////////////////////////////////////////////////// class StackApp { public static void main(String[] args) { StackX theStack = new StackX(10); // make new stack theStack.push(20); // push items onto stack theStack.push(40); theStack.push(60); theStack.push(80); while( !theStack.isEmpty() ) // until it’s empty, { // delete item from stack long value = theStack.pop(); System.out.print(value); // display it System.out.print(“ “); } // end while System.out.println(“”); } // end main() Stacks 121 LISTING 4.1 Continued 05 0672324539 CH04 10/10/02 9:09 AM Page 121} // end class StackApp -
1. kodu çevireyim
System.Collections.Generic.Queue<long> q = new System.Collections.Generic.Queue<long>();
q.Enqueue(...)
q.Dequeue(..)2. kod
System.Collections.Generic.Stack<int> s=new Stack<int>();
s.Pop(...)
s.Push(...):)
-
HolyOne bunu yazdı
1. kodu çevireyim
System.Collections.Generic.Queue q = new System.Collections.Generic.Queue();
q.Enqueue(...)
q.Dequeue(..)2. kod
System.Collections.Generic.Stack s=new Stack();
s.Pop(...)
s.Push(...):)
bu nasıl birşey şeyhim.200 sayfalık kitabı el broşürüne özet dökmüşsün gibi oldu :)
-
bu kodları olduğu gibi visual studio ya kopyala.
derlenecektir. sadece şu kısmı değiştirmen lazım.
publicstaticvoidmain(String[] args) -
HolyOne bunu yazdı
1. kodu çevireyim
System.Collections.Generic.Queue q = new System.Collections.Generic.Queue();
q.Enqueue(...)
q.Dequeue(..)2. kod
System.Collections.Generic.Stack s=new Stack();
s.Pop(...)
s.Push(...):)
normal değil :)
-
bu senin data structures ödevin demi ? =))
-
AyT bunu yazdı
bu senin data structures ödevin demi ? =))
haha bizim hoca da geçen sene vermiş bunun aynısını :)
-
HolyOne bunu yazdı
1. kodu çevireyim
System.Collections.Generic.Queue q = new System.Collections.Generic.Queue();
q.Enqueue(...)
q.Dequeue(..)2. kod
System.Collections.Generic.Stack s=new Stack();
s.Pop(...)
s.Push(...):)
i love you filmindeki gibi oldu sanki adam ingilizce konuşuyor ne dedi diyor bilmem kısa bir cüme söylüyor. adam bir araba dolusu laf söyledi bunu mu demek istedi :D
