Skip to main content

Posts

Queues with Java API

And continuing with the Queues the next thing did was making a queue with java API. The thing is Queue is an interface for java. The details in the standard API can be seen here . As usually did the standard and simplest functions just to get a hang of it. add( value ); for adding elements for the group always remember in Queue FIFO remove(); Removes the first in line peek(); Gives a glance of the first/ head element without removing it element(); The same as about except in above if the Queue is empty it will return null but in element(); if the Queue is empty it will give an exception. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 import java.util.LinkedList ; import java.util.Queue ; public class QueueFromAPI { public static void main ( String args []) { Queue A = new LinkedList (); A . add (30); A . add (100); A . add (70); A . add (567); System . out . println ( "First Element " + A ....

AngularJS Basics again

Thought of doing basics of AngularJS again and ended up following W3School tutorials which are pretty good. So here is what I learned. 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 <!doctype html> <html lang="en" > <head> <meta charset="utf-8" > <title> Back to Basics </title> <link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.css" > <link rel="stylesheet" href="css/app.css" > <script src="bower_components/angular/angular.js" ></script> </head> <body > <!--ng-app is given in div tag and where the application begins--> <!--ng-init initialize the application variables--> <!-- 3rd line ng-init creating the object vehicle--> <!-- final line is defining an array--> <div ng-app ng-init="Numone = 3 ; NumTwo = 5 ; ...

Starting with Queues

So in this post no more about stack its all about queues. When talking about queues the first thing that comes in to our mind is the movie queue. What happens there is the earlier you come the best chance of getting a good seat. Likewise in here this data structure is also like a movie queue. It serves elements in F irst I n F irst O ut (FIFO) basis. The elements are added in the rear and must be remove prom the front. That's right in stacks we had our concern only on the top element but here we need to keep our concern on two elements rear and front .  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 public class QueueOne { private int MaxSize ; // size of the array private int [] arr ; // the queue private int rear ; // the back element private...

Simple stack using Java API

So the things that I did in above post can be single handedly done by Java API. The API for Stacks can he accessed from here . So here is an small example illustrating few of its functions. Remember to import the package java.util.Satck. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 import java.util.Stack ; public class StackFromAPI { public static void main ( String [] args ) { Stack x = new Stack (); x . push ( 20 ); x . push ( 40 ); x . push ( 50 ); System . out . println ( "pop top one " + x . pop ()); System . out . println ( "pop next top one " + x . pop ()); System . out . println ( "pop next top one " + x . pop ()); if ( x . isEmpty () == true ){ System . out . println ( "now this is empty" ); } } }

Unexpected Success in Filtering Repeters

So thought the previous post was the last one, but guess what I was just having a typo in the controller. This is huge relief for me. Here what I followed from the tutorial was that you can actually create a controller for your app, and Include it using ng-controller. Controller is actually a function that use $scope . Through this the model and controller work together. So here is the Controller; 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 /* Controllers */ var myApp = angular.module( 'myApp' ,[]); myApp.controller( 'namectrl' , function ($scope){ $scope.names = [ { 'Fname' : 'anna' , 'Lname' : 'kendrick' }, { 'Fname' : 'jason' , 'Lname' : 'mraz' }, { 'Fname' : 'jennifer' , 'Lna...

Angular Basics

So going through many times here and there didn't achieve the best of things but learned a lot. This is the very basic thing that I produced up to now. This explains the dynamic nature of how views changes when the model changes. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 <!DOCTYPE html> <html ng-app > <head lang= "en" > <meta charset= "UTF-8" > <title> Testing Angular </title> <script src= "bower_components/angular/angular.js" ></script> <link rel= "stylesheet" href= "bower_components/bootstrap/dist/css/bootstrap.css" > <link rel= "stylesheet" href= "css/app.css" > <script src= "js/controllers.js" ></script> </head> <body> <div style= "padding-left: 100px" > <input ng-model= "typeone" /> </div> ...

Finishing with Stacks

So this will be the last one on stacks. Here I'll talk about the places where stacks will be used.  One most popular place this is used is the undo and redo buttons. When you change something the changes are placed in a stack and for some reason when you undo it, it'll pop the top change back. Another place would be in the web browser. The history of you visited page addresses will be in a stack. When you click back it will direct to the previous page. JVM itself is a stack oriented VM just like most of them. In operating systems the stacks keeps the return addresses when functions are called from another function. The stack will provide the jump address when its done. That will be all about stacks. So if you are interested do Experiments .