Posts

Showing posts from June, 2021

queue_in_java

  package com.company ; import java.util.LinkedList ; import java.util. Queue ; public class queu_in_java { public static void main ( String [] args ) { Queue < Integer > q = new LinkedList <>(); // adds elements {0, 1, 2, 3, 4} to // the que for ( int i = 0 ; i < 5 ; i ++) q . add ( i ); // display content of the queue System . out . println ( "Element of the queu " + q ); // remove the head of the queue int removablle = q . remove (); System . out . println ( "removed element is -" + removablle ); System . out . println ( q ); //to view head of the queue int head = q . peek (); System . out . println ( "head of the queue-" + head ); int size = q . size (); System . out . println ( "size of the queue - " + size ); } }

stack_in_java

  // Java code for stack implementation package com.company ; import java.io. *; import java.util. *; class stack { // Pushing element on the top of the stack static void stack_push ( Stack < Integer > stack ) { for ( int i = 0 ; i < 5 ; i ++) { stack . push ( i ); } } // Popping element from the top of the stack static void stack_pop ( Stack < Integer > stack ) { System . out . println ( "Pop Operation:" ); for ( int i = 0 ; i < 5 ; i ++) { Integer y = ( Integer ) stack . pop (); System . out . println ( y ); } } // Displaying element on the top of the stack static void stack_peek ( Stack < Integer > stack ) { Integer element = ( Integer ) stack . peek (); System . out . println ( "Element on stack top: " + element ); } // Searching element in the stack static void stack_search (

fastinput and output in java using Bufferreader class

  package com.company ; import java.io.BufferedReader ; import java.io.IOException ; import java.io.InputStreamReader ; class Employeeupdate { String name ; int id ; int age ; Employeeupdate ( String name , int age , int id ){ this . name = name ; this . age = age ; this . id = id ; } public void displayDetails (){ System . out . println ( "Name: " + this . name ); System . out . println ( "Age: " + this . age ); System . out . println ( "Id: " + this . id ); } } public class update { public static void main ( String [] args ) throws IOException { BufferedReader sc = new BufferedReader ( new InputStreamReader ( System . in )); System . out . println ( "Enter your name:" ); String name = sc . readLine (); System . out . println ( "Enter your age:" ); int age = Integer . parseInt ( sc . readLine ()); System . out