jistyle.jty
BAN USER
Iterative method using Queue:
Aux storage:
Queue traverseQueue
List<LinkedList> or LinkedList[maxLevelOfTree]
int levelIndex
Psuedo code:
traverseQueue.add(root);
levelIndex = 0;
while (traverseQueue.Size() > 0) {
LinkedList head = new LinkedList();
LinkedList current = head;
for (int temp = traverseQueue.size(); temp > 0; temp--) {
TreeNode temp = traverseQueue.remove();
current.value = temp.value;
for (TreeNode child : temp.childs) {
traverseQueue.add(child);
}
if (temp > 1) {
// if not the last node of current level
current.next = new LinkedList();
current = current.next;
}
}
listOfLinkedList[levelIndex] = head;
levelIndex++;
}
return listOfLinkedList;
I think this is a question about data structure and OOP design..
Each tweet would be a tree node, with an original tweet being the root.
Each node contains a tweet object, which holds list value of favorites, a formatted string, a bitmap image, and a list of people in the conversation ("@person 1", "@person 2") and the child nodes may be retweets (which are also tree nodes).
Then we may have a linked list of tweets, which is the replies (conversation)
All tweets, retweets, and replies are tweet objects which is all in a giant map that has the tweet ID as a key and tweet object as value..
I don't use twitter so these are just ideas out of my brain :)
I'm sure there are different structures, such as an abstract tweet object with child classes such as retweet, reply, and root tweet, which holds different properties.
I guess it all comes down to what you personally think is the best structure.
Repmarkglove17, Associate at Arista Networks
Hi, I am Mark from North Edwards, CA .I am just crazy about dance.I am not professionally trained, but ...
Repjennifertkramer, AT&T Customer service email at ADP
I had a dream to open my own Restaurant in FL. and i came true all dream with my hard ...
RepRussBDycus, Android test engineer at ABC TECH SUPPORT
I am working as a manager in Lionel Kiddie City company. I really enjoy my job. I like to play ...
Repsusancmeans, Apple Phone Number available 24/7 for our Customers at Absolute Softech Ltd
I am Susan from Bronx, I am working as a Business management analyst in Brendle's company. I Have a ...
Repfredlhenry, Android Engineer at Digital Merkating
Hi, I am Fred, 27 years old, I have done bachelor’s in IT.I have been working for a ...
Repaaronmdunlap6, Area Sales Manager at Achieve Internet
Hi, I am an HR Analyst with extensive experience delivering innovative solutions at the corporate level. Expertise in employee relations ...
Repbarrybzane, AT&T Customer service email at ASU
By Profession, I am a Child protective services social worker in Newark USA. My strong interest is in yoga. My ...
Repcharlespladd, Android Engineer at Abs india pvt. ltd.
I am Charles from Pascoag USA. I have strong knowledge of pain management systems. And I have experience in providing ...
Repkathimhoke, Product Security Engineer at Argus
Hi, I am Kathi from Mineola. I am working as an Identification clerk in a Tradewell company. I spent over ...
sounds about right in your english explanation, except you aren't adding a new null to the end of the queue, so this code will never be able to determine the end of the level after the root level :P
- jistyle.jty March 13, 2015The loop is adding the left and right to the queue only if it is not null, which will reiterate in a recursive fashion to repeat adding non-null lefts and rights, which means you are never adding an extra null.