Skip to main content

Posts

Showing posts from February, 2015

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 .

Further with Stacks

So done with Push and Pop. Then lest go further with some more functions. Here I'm gonna present the code for peek in a stack, check if its empty and check if its full.  Peek is just having a look at the top element in the stack. Wait so does the pop , what's the difference? The difference is pop removes the element and peek does not, it only gives a sneak peek. Since the other two are more obvious Lets get straight to code: 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 public class StackA { private int MaxSize ; // size of the stack private int [] arr ; // the stack private int top ; // the top element public StackA ( int s ){ // constructor initiate stack MaxSize = s ; // assign the size arr = new int [ s ]; //creating the stack top = - 1 ; // initial top element } ...

Algorithms with Stacks

So thought of training with some stack in the beginning of algorithms. I'm gonna use java for the coding. So as the word says its a stack, like a stack of plate. what is special about it is how the elements come in and out of it. The first plate to come in is the first plate to get out. we call this F ist I n F irst O ut (FIFO). Without further ado lets go straight in to the code. The first thing I created was the stack. Here in Class StackA I initially defined the array, array size and the top elemen t. 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 public class StackA { private int MaxSize ; // size of the stack private int [] arr ; // the stack private int top ; // the top element public StackA ( int s ){ // constructor initiate stack MaxSize = s ; // assign the size arr = new int [ s ]; //creating the stack top = - 1 ; // initi...

PhpStorm and AngularJS

As the IDE for coding I use Phpstorm 8. The reasons are its quite easy to handle. But I thought it would be great that if it can provide auto-complete AngularJS tags and JavaScript etc. With that when I look into a solution it was a simple thing to do. Simple as Just install the plugin. You can do that by going to file>settings or Ctrl+Alt+S Then you'll get a settings window. This will show a tab named plugins.  Then in there click the install jetBrains plugin plugins and choose AngularJS then install it. After that Restart the browser and tadaa you are good to go.

Starting With AngularJS

So a per the tutorial said. First installed git. Then cloned to the tutorial repository which was given  Phonecat . Then installed nodes.js and finally did a npm install which took me almost 20 min. I wonder why? The npm install did installed the following ; Bower   - client-side code package manager Http-Serve r  - simple local static web server Karma   - unit test runner Protractor   - end to end (E2E) test runner So I'm all ready to go. 

Something to start with

I'm Anjula Ranasinghe an undergraduate of University of Moratuwa, Sri Lanka. I starts this blog hoping to share everything that I do while coding. Codes ,questions, headaches etc. Hope to continues this for a long time. So wish me luck.