import java.util.*; public class Question4_3 { static class Node { Integer data; Node left; Node right; public Node(Integer data) { this.data = data; } public int height() { int leftHeight = left != null ? left.height() : 0; int rightHeight = right != null ? right.height() : 0; return 1 + Math.max(leftHeight, rightHeight); } public boolean isBalanced() { int leftHeight = left != null ? left.height() : 0; int rightHeight = right != null ? right.height() : 0; return (Math.abs(leftHeight - rightHeight) <= 1); } } public static Node minimalBST(int[] sorted) { return minimalBST(sorted, 0, sorted.length - 1); } private static Node minimalBST(int[] sorted, int start, int end) { if (start > end) { return null; } int mid = (start + end) / 2; Node node = new Node(sorted[mid]); node.left = minimalBST(sorted, start, mid - 1); node.right = minimalBST(sorted, mid + 1, end); return node; } public static Node insert(Node node, Integer data) { if (data == null) { return null; } if (node == null) { node = new Node(data); return node; } if (data.compareTo(node.data) <= 0) { if (node.left == null) { node.left = new Node(data); } else { insert(node.left, data); } } else { if (node.right == null) { node.right = new Node(data); } else { insert(node.right, data); } } return node; } public static void main(String[] args) { int[] array = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; Node root = minimalBST(array); System.out.println("Root? " + root.data); // System.out.println("Created BST? " + root.isBST()); System.out.println("Height: " + root.height()); System.out.println("Is balanced? " + root.isBalanced()); Random random = new Random(); root = null; array = new int[20]; for (int i = 0; i < array.length; i++) { array[i] = random.nextInt(array.length); root = insert(root, array[i]); System.out.print(array[i] + " "); } System.out.println(); // root = minimalBST(array); System.out.println("Root? " + root.data); System.out.println("Height: " + root.height()); System.out.println("Is balanced? " + root.isBalanced()); } }
public class ExamplePupAge { int age; public void pup(int age) { age = age + 1; System.out.println("My pup's age is: " + age); } public static void main(String[] args) { ExamplePupAge doggy = new ExamplePupAge(); doggy.pup(1); } }
//Caixa.java: public class Caixa { //Variaveis de classe //O volume total e compartilhado: public static double volumeTotal = 0; //Atributos especificos: private double altura; private double comprimento; private double largura; //Construtor: public Caixa(double a, double b, double c) { altura = a; comprimento = b; largura = b; volumeTotal = volumeTotal+(altura*comprimento*largura); } //Metodo calcular volume: public double volume() { return altura*comprimento*largura; } }
public class HelloWorld{ public static void main(String []args){ System.out.println("Hello World"); } }
#import <Foundation/Foundation.h> int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSLog (@"hello world"); [pool drain]; return 0; }
#include <iostream> using namespace std; int main() { //printing any name cout << "Ranjit kumar" << endl; return 0; }
#include <stdio.h> int main() { for (; 0;) { printf("Hello it will execute"); } return 0; }
//============================================================================ // Name : DFS_AssignmentNo1.cpp // Author : Rushikesh // Version : // Copyright : @rushikesh // Description : Hello World in C++, Ansi-style //============================================================================ #include <iostream> using namespace std; #define MAX 100 class LinearArray { public: long int ACN; string FNAME, LNAME; int FEES, YEAR; void insert(); void display(); //void searchbyyear(int year); //void searchbyfees(int fee); }; void LinearArray::insert() { cout << "\n************************************************************"; cout << "\nEnter the Adhar Card No.:"; cin >> ACN; cout << "\nEnter the first name:"; cin >> FNAME; cout << "\nEnter the Last name:"; cin >> LNAME; cout << "\nEnter the fees:"; cin >> FEES; cout << "\nEnter the Year:"; cin >> YEAR; cout << "\n************************************************************"; } void LinearArray::display() { cout << "\n************************************************************"; cout << "\nAdhar card NO.=" << ACN; cout << "\nFirst Name=" << FNAME; cout << "\nLast name=" << LNAME; cout << "\nFees=" << FEES; cout << "\nYear=" << YEAR; cout << "\n************************************************************"; } int main() { static int STRENGTH = 0; LinearArray a[30]; int ch1, n, fee, year, temp = 0; char ch2; do { cout << "************************************************************"; cout << "\n1.Insert record\n2.Display records\n3.Search records by using Fees\n4.Search by using Year"; cout << "\n************************************************************"; cout << "\nEnter your choice:"; cin >> ch1; switch (ch1) { case 1: cout << "\nHow many records you want to insert...?"; cin >> n; temp += n; while (STRENGTH < temp) { a[STRENGTH].insert(); STRENGTH++; } break; case 2: for (int i = 0; i < STRENGTH; i++) { a[i].display(); } break; case 3: cout << "\nEnter the fees:"; cin >> fee; cout << "\nDetails of the Students whose Fees are " << fee << " and more than " << fee << ":"; for (int i = 0; i < STRENGTH; i++) { if (a[i].FEES >= fee) { cout << "\nAdhar card NO.=" << a[i].ACN; cout << "\nFirst Name=" << a[i].FNAME; cout << "\nLast name=" << a[i].LNAME; cout << "\nYear=" << a[i].YEAR; } } break; case 4: cout << "\nEnter the year:"; cin >> year; cout << "\nDetails of the Students whose year is " << year; for (int i = 0; i < STRENGTH; i++) { if (a[i].YEAR >= year) { cout << "\n************************************************************"; cout << "Adhar card NO.=" << a[i].ACN; cout << "First Name=" << a[i].FNAME; cout << "Last name=" << a[i].LNAME; cout << "Fees=" << a[i].FEES; cout << "\n************************************************************"; } } break; default: cout << "\nInvalid Choice!!!"; break; } cout << "\nDo you want to continue...?(Y/N):"; cin >> ch2; } while (ch2 == 'Y' || ch2 == 'y'); return 0; }
#include <stdio.h> int main() { printf("Hello, World!\n"); return 0; }
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more