₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,325,252 members, 8,420,983 topics. Date: Friday, 05 June 2026 at 03:55 PM

Toggle theme

Javanian's Posts

Nairaland ForumJavanian's ProfileJavanian's Posts

1 2 3 4 5 6 7 8 ... 39 40 41 42 43 44 45 46 47 (of 57 pages)

ProgrammingRe: Dynamic Programming Puzzle by Javanian: 9:59am On Nov 16, 2012
Thanks @prince
ProgrammingRe: [C++ Open Source] Relax! ( File Management Tool) by Javanian: 9:58am On Nov 16, 2012
Nice thread, Nice project cool
ProgrammingRe: Dynamic Programming Puzzle by Javanian: 3:14am On Nov 15, 2012
@ekt_bear and @prince can i see a java implementation of your code?
ProgrammingRe: Sorting List Of Numbers And Strings: Simple Puzzle by Javanian: 8:11am On Nov 13, 2012
Nice one...quite similar to mine...
ProgrammingRe: Sorting List Of Numbers And Strings: Simple Puzzle by Javanian: 7:00am On Nov 13, 2012
Can i see your java implementation?
ProgrammingRe: Sorting List Of Numbers And Strings: Simple Puzzle by Javanian: 12:22pm On Nov 12, 2012
@ekt_bear we go fry egg for you huh
ProgrammingRe: Sorting List Of Numbers And Strings: Simple Puzzle by Javanian: 6:45am On Nov 11, 2012
Where is @ekt_bear??
ProgrammingRe: Storing K largest numbers from a stream by Javanian: 2:33am On Nov 11, 2012
@ekt_bear i'm sorry for the late reply there has been shortage of power in my area.

O.k. I tried implementing it with a BST it worked but it was no different from when i did it with a heap. It will take O(log2n) time at worst case. Although i have to admit that suggesting a BST at first was wrong, what i had in mind was something like a Binary Heap which will return the maximum item in O(1) time at worst case. But it is more or less useless because I'm not going to be inserting all the items. So i wont be able to take advantage of this...
ProgrammingRe: Sorting List Of Numbers And Strings: Simple Puzzle by Javanian: 1:02am On Nov 11, 2012
^^^ sorry, what part of the code do you have problem with?
ProgrammingRe: Sorting List Of Numbers And Strings: Simple Puzzle by Javanian:

/*****
* I solved this some 35 hours ago but PHCN wont let me post it mstcheeeww!!! angry
*/

import java.util.*;
public class SortBlaBla {

public static void main(String[] args)
{
//read from statndard input bla bla bla
String input ="1 this a 8 for 7 z you s d 1";
int max = input.length();
Queue theInputQueue = new Queue(max);
Queue theIntQueue = new Queue(max);
Queue theStringQueue = new Queue(max);

String[] firstArray = input.split("\\s"wink;
for(int i=0; i<firstArray.length; i++)
{
theInputQueue.insert(String.valueOf(firstArray[i]));
}
Arrays.sort(firstArray);
for(int i=0; i<firstArray.length; i++)
{
if(isInt(firstArray[i].toString()))
{
theIntQueue.insert((firstArray[i]));
}
else
{
theStringQueue.insert(firstArray[i]);
}
}
while(!theInputQueue.isEmpty())
{
if(isInt(theInputQueue.remove()))
System.out.println(theIntQueue.remove());
else
System.out.println(theStringQueue.remove());

}
}
//Check if a value is an integer
public static boolean isInt(String s)
{
try
{
Integer.parseInt(s);
}
catch(NumberFormatException ex)
{
return false;
}
return true;
}
}
//you can ignore this part of the code...you can replace it with a STL
class Queue
{
private int maxSize;
private String[] queArray;
private int front;
private int rear;
private int nItems;

Queue(int s)
{
maxSize = s;
queArray = new String[maxSize];
front = 0;
rear = -1;
nItems = 0;
}

void insert(String 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 String remove()
{
String temp = String.valueOf(queArray[front++]);
if(front == maxSize)
front = 0;
nItems--;
return temp;
}
public String peekFront() // peek at front of queue
{
return queArray[front];
}
boolean isEmpty() // true if queue is empty
{
return (nItems==0);
}
boolean isFull() // true if queue is full
{
return (nItems==maxSize);
}
int size() // number of items in queue
{
return nItems;
}
}
//Boy!...Never new it would be more difficult to post a code than writing the actual code...P.H.C.N i dey hail o! mstcheeew!! angry angry angry angry angry angry
ProgrammingRe: Storing K largest numbers from a stream by Javanian: 10:51pm On Nov 04, 2012
ekt_bear: Why not use the java collections heap rather than implementing your own?
Actually, I've been looking for an opportunity to implement it grin , Thanks for giving me one...
ProgrammingRe: Storing K largest numbers from a stream by Javanian:
with a HEAP

class Node
{
private int iData;

Node(int key)
{ iData = key; }

int getKey()
{ return iData; }

void setKey(int id)
{ iData = id; }
}
class Heap
{
private Node[] heapArray;
private int maxSize; // size of array
private int currentSize; // number of nodes in array

Heap(int mx)
{
maxSize = mx;
currentSize = 0;
heapArray = new Node[maxSize];

for(int i=0; i<heapArray.length; i++)
{
Node newNode = new Node(0);
heapArray[i] = newNode;
currentSize++;
}
}

boolean isEmpty()
{ return currentSize==0; }

boolean insert(int key)
{
for(int i=0; i<heapArray.length; i++)
{
Node newNode = new Node(key);
while(newNode.getKey() > heapArray[i].getKey())
{
Node temp = heapArray[i];
heapArray[i] = newNode;
change(i+1, temp.getKey());
trickleUp(i);
return true;
}
}
return true;
}

void trickleUp(int index)
{
int parent = (index-1) / 2;
Node bottom = heapArray[index];
while( index > 0 &&
heapArray[parent].getKey() < bottom.getKey() )
{
heapArray[index] = heapArray[parent]; // move it down
index = parent;
parent = (parent-1) / 2;
}
heapArray[index] = bottom;
}

public boolean change(int index, int newValue)
{
if(index<0 || index>=currentSize)
return false;
int oldValue = heapArray[index].getKey(); // remember old
heapArray[index].setKey(newValue); // change to new
if(oldValue < newValue) // if raised,
trickleUp(index); // trickle it up
return true;
}
public void displayHeap()
{
for(int i=0; i<heapArray.length; i++)
{
System.out.println(heapArray[i].getKey());
}
}

}
class HeapApp
{
public static void main(String[] args)
{
Heap theHeap = new Heap(2);
theHeap.insert(7000000);
theHeap.insert(4000);
theHeap.insert(50000);
theHeap.insert(20);
theHeap.insert(-1);
theHeap.insert(100);
theHeap.insert(8000);
theHeap.insert(30);
theHeap.insert(10);
theHeap.insert(900000000);

theHeap.displayHeap();


}
}
ProgrammingRe: Does Anyone Know How This Feauture In Facebook Was Created? by Javanian(op): 7:58am On Nov 03, 2012
Thanks for the tips @all
ProgrammingRe: Storing K largest numbers from a stream by Javanian: 10:41pm On Oct 31, 2012
Yeah!...i know of heap and priority queues...i will attempt your suggestion when am on p.c. Although i would have prefered using something like a Binary search tree
ProgrammingRe: Storing K largest numbers from a stream by Javanian: 9:06pm On Oct 31, 2012
Like i said I'm writing from a mobile phone so i overlooked a lot of things but those should be easy to fix right?
ProgrammingRe: Storing K largest numbers from a stream by Javanian:

/**PHCN has decided to abandon us, so i wrote this code from a mobile phone, if it works its my code else @ekt_bear wrote it grin
***/

import java.util.*;
public class TopK
{
//assuming k is 5
int k=5;
int[] numbers;

public TopK()
{
numbers = new int[k];
for(int i=0; i< numbers.length; i++)
{

numbers[i]=0;
}
}
public void insert(int n)
{
//sort the arrays in ascending order
Arrays.sort(numbers);
for(int i=0; i<=numbers.length; i++)
{
if(n>numbers[i])

numbers[i]=n;
break;
}
}
public void print()
{
for(int i=0; i<numbers.length; i++)
System.out.println(numbers[i]);
}
public static void main(String[] args)
{
TopK tp = new TopK();
//Here you will read @ekt_bear 1 Zillion numbers and insert them individually e.g tp.insert(read.nextInt)
//but for sake of convinience i will just insert some numbers to test it

tp.insert(90);
tp.insert(40);
tp.insert(100);
tp.insert(60);
tp.insert(10);
tp.insert(80);
tp.insert(110);
tp.insert(1000);
tp.insert(260);
tp.insert(10);
tp.print();
}

}

ProgrammingRe: Storing K largest numbers from a stream by Javanian: 8:22am On Oct 31, 2012
Is memory a problem?
ProgrammingRe: Help A Frustrated Programmer With Power Problem by Javanian: 8:21pm On Oct 29, 2012
goon: U be heavy mumu...
GBAM!!!!!!! Very Big Mumu!
ProgrammingRe: Help A Frustrated Programmer With Power Problem by Javanian: 8:21pm On Oct 29, 2012
informatix: I am a programmer infact one of the Best in Nigeria. I learn how to program with a Laptop whose power doesnt Last for 1munite. I strongly DON'T agree power is a boundary in leraning programming.
A serious programmer should be able to know where to get 24hours light.cafe,bizcenter,govt. Office. I once travelled 150km to get a condusive environment to Start Apache tomcat version4 using java virtual machine.


import java.io.*;

class naija{
public Static void main(String args[]){
public String ans;
Bufferedreader input=new Bufferedreader(New Inputstreamreader(System.read());
System.out.print("I dont believe power shortage is a boundary to learning how to program"wink;

System.out.print("what do u think?"wink;
ans=input.readLine();
System.out.println(" you said"+ans);
}}

compile=javac naija.java
execute=java naija
You are nothing but a Noise Maker...see the rubbish code you wrote after all the mouth...
ProgrammingRe: Does Anyone Know How This Feauture In Facebook Was Created? by Javanian(op): 8:17pm On Oct 29, 2012
spikes C: research on Erlang, am on mobile, should have wrote you a comprehensive answer. and No, its not embedded on the web application. It runs seperately, i've don a very deep research on it. i even have an e-book they wrote on it.
Please when you are on P.c. try and give a comprehensive answer. I will really appreciate it...
ProgrammingRe: Does Anyone Know How This Feauture In Facebook Was Created? by Javanian(op): 7:25pm On Oct 29, 2012
What of the feature for online members? Do you know what they use and how they do it? I think they use AJAX but i might be wrong...
ProgrammingRe: Does Anyone Know How This Feauture In Facebook Was Created? by Javanian(op): 7:22pm On Oct 29, 2012
Thanks alot...i really appreciate...
ProgrammingRe: Does Anyone Know How This Feauture In Facebook Was Created? by Javanian(op): 5:17pm On Oct 29, 2012
Thanks for your reply but Is the chat application a stand alone embedded in the web application with server push/web sockets? Can you please throw more light on this?
ProgrammingDoes Anyone Know How This Feauture In Facebook Was Created? by Javanian(op): 3:48pm On Oct 29, 2012
Was on Facebook today and i was wondering how their embedded chat application was created. Does anyone have an idea?

ProgrammingRe: Java SE, EE & Scala Developers - Lets Connect And Share Knowledge by Javanian:
^^^^ Next time create your own thread...you are derailing this thread... here is your code...http://pastebin.com/8NuPiKXE
Foreign AffairsRe: Donald Trump Offers Obama $5Million In Exchange For College Records by Javanian: 10:32pm On Oct 24, 2012
Bloody publicity stunt!!!....
European Football (EPL, UEFA, La Liga)Re: UCL: Dortmund Vs Real Madrid (2 - 1) On 24th October by Javanian: 10:20pm On Oct 24, 2012
toba: thats the problem. who told u madrid is the 2nd best team in the world? pls stop spreading false stat. when last did this ur madrid played in the UCL final? whats their position on the table for this season's laliga? whats the source of this info?
Then which team is? chelsea? Man Utd? man city? Arsenal? Bayern munich? Dortmund?

I'm not a Madrid fan...infact am more of a madrid hater but we all know the truth...This Dortmund will be at the mercy of Madrid on a good day
European Football (EPL, UEFA, La Liga)Re: UCL: Dortmund Vs Real Madrid (2 - 1) On 24th October by Javanian: 10:06pm On Oct 24, 2012
toba: I know Barca. that team from spain that plays all passing game, yet couldnt beat Madrid in the first el classico with iniesta, xavi, pedro, messi.
You cant win every day man undecided Take it or leave it Madrid is the second best team in the world....I just said they are over hyped...and thats the truth..
European Football (EPL, UEFA, La Liga)Re: UCL: Dortmund Vs Real Madrid (2 - 1) On 24th October by Javanian: 9:52pm On Oct 24, 2012
CFCfan: Real Madrid made history tonight. They are the first team to score in 17 consecutive Champions League matches.
who cares?undecided
European Football (EPL, UEFA, La Liga)Re: UCL: Dortmund Vs Real Madrid (2 - 1) On 24th October by Javanian: 9:50pm On Oct 24, 2012
toba: Dortmund is just too big for madrid. barca sef. go try but cant beat dortmund over two legs
undecided undecided you don't know Barca...Dortmund won't even have the mind to attack against Barca like they did to madrid...
European Football (EPL, UEFA, La Liga)Re: UCL: Dortmund Vs Real Madrid (2 - 1) On 24th October by Javanian: 9:28pm On Oct 24, 2012
Stupid over hyped Madrid team...Na only against Barca them dey get mind..

Viva Barca jooor!!!
WebmastersRe: by Javanian: 10:28am On Oct 22, 2012
Create this thread in the web masters section, they will help you there...

1 2 3 4 5 6 7 8 ... 39 40 41 42 43 44 45 46 47 (of 57 pages)