View Feed
group-icon
Coffee Room
Discuss anything here - everything that you wish to discuss with fellow engineers.
12915 Members
Join this group to post and comment.
vinod1993
vinod1993 • Sep 11, 2012

Need some easily understandable examples to understand Stacks,Queue's and linked lists better.

I'm very new to programming(Yes,programming existed in my school days,but I ignored them a lot as I had the least interest then). But now, I find Programming very interesting and I have developed a ever-lasting thirst for learning it(I'm slowly learning it one by one, now stuck in C and C++). But,I'm not able to understand Stacks,queues and linked lists to the best extent.Someone please help me with my difficulties with easily understandable examples. And teach me about pointers too. Please.Yes, I can go through tutorials and books to get a clear cut information but In my opinion interaction leads to better inderstanding than the rest. 😀 And one more thing What advantages does C# have over C++. I do not know C# at all, but would love to know. 😀
Jeffrey Arulraj
Jeffrey Arulraj • Sep 11, 2012
count me in i am in big trouble cos of data structures
Sure you can post your doubts one by one here and we can then interact.. Regarding advantages of C# over C++, there are a whole bunch of new concepts in c# compared to c++. Some of them are the likes of partial classes, delegates, events etc and a biggest advantage is garbage collection that makes the use of destructor out of the question. C# was developed by MIcrosoft to have direct competition with Java. So you can, in many ways consider C# to be in the league of Java
Anoop Kumar
Anoop Kumar • Sep 12, 2012
Data structures are considered to toughest for beginners.. strange names, lots of algorithm and sudo codes.
But truth is , it seems interesting when you start relating data structures to day to day real things.
Every one have encountered with Stack, Queue, List, LinkedList blah blah... Aren't they??
Jeffrey Arulraj
Jeffrey Arulraj • Sep 12, 2012
can you guys explain traversing of a list
optimystix@
optimystix@ • Sep 12, 2012
hey first refer the book of yashwant kanetkar "Data Structures Through C" even after rafering the book u have the query i will give u the java code of structures
Anoop Kumar
Anoop Kumar • Sep 12, 2012
jeffrey samuel
can you guys explain traversing of a list
going to every item of list is traversing. Major use is find desired item in least time.
For example: you got the shopping list how you fing a item from it. one way is just look for the item from top and go towards the bottom.
optimystix@
optimystix@ • Sep 12, 2012
Traversing is more similar to searching of element in the list in least possible time u can use binary search tree for it it's best for searching
*binary search tree*

import java.io.*;
class node
{
int data;
node l;
node r;
public node(int i)
{
data=i;
l=null;
r=null;
}
}
public class bst
{
node root=null;
node head=null;
void create(node p,node temp)
{
if(temp.data {
if(p.l==null)
{
p.l=temp;
return;
}
else
{
create(p.l,temp);
}
}
else
{
if(p.r==null)
{
p.r=temp;
return;
}
else
{
create(p.r,temp);
}
}
}
void inorder(node t)
{
if(t!=null)
{
inorder(t.l);
System.out.println(t.data);
inorder(t.r);
}
}
void preorder(node t)
{
if(t!=null)
{
System.out.println(t.data);
preorder(t.l);
preorder(t.r);
}
}
void postorder(node t)
{
if(t!=null)

{
postorder(t.l);
postorder(t.r);
System.out.println(t.data);
}
}
public static void main(String[] args)throws IOException
{
DataInputStream input=new DataInputStream(System.in);
bst b=new bst();
int ch,item,n;
do
{
System.out.println("1-create");
System.out.println("2-inorder");
System.out.println("3-preorder");
System.out.println("4-postorder");
System.out.print("Enter your choice:");
ch=Integer.parseInt(input.readLine());
switch(ch)
{
case 1:
System.out.print("Enter n:");
n=Integer.parseInt(input.readLine());
for(int i=0;i {
System.out.println("Enter the item:");
item=Integer.parseInt(input.readLine());
node temp=new node(item);
if(b.head==null)
b.head=temp;
else
b.create(b.head, temp);
}
break;
case 2:
b.inorder(b.head);
break;
case 3:
b.preorder(b.head);
break;
case 4:
b.postorder(b.head);
break;
}
}while(ch<=3);
}
}
vinod1993
vinod1993 • Sep 13, 2012
I am not able to visualise the use of pointers properly. for eg. I'm completely able to understand the array implementation of a stack but am not able to understand linked list implementation of stacks. Why? because, I am not able to visualise pointers properly. Please help me. 😀
vinod1993
I am not able to visualise the use of pointers properly. for eg. I'm completely able to understand the array implementation of a stack but am not able to understand linked list implementation of stacks. Why? because, I am not able to visualise pointers properly. Please help me. 😀
The best way to understand is the "paper and pen" method.
Draw the diagram regarding the thing you are trying to do. You'll understand easily what you have to link.
This goes for all linked list programs.
simplycoder
simplycoder • Sep 17, 2012
Linked Lists arent that tough(They are when they are introduced), but later they dont matter much.

First of all, its not mandate to visualize stack as a top to bottom array, where top is the place from where the elements are removed.

If I were to visualize stacks in linked list, I visualize it as train
where one bogie is connected to another.

Assume that engine is the top so when you want to remove a bogie, in stack fashion, you can remove it only from the engine side and then attach engine to the new bogie same thing when adding.

Now correlate this with address of top and engine, I think this picture will get you clear.

Look around, world is full of data-structures and algorithms.
simplycoder
simplycoder • Sep 17, 2012
optimystix@
Traversing is more similar to searching of element in the list in least possible time u can use binary search tree for it it's best for searching
I don't quiet agree with the term 'least'(no offense) here as a good hash function will have O(1) time where as Binary tree search will have O(lg(n)) theoretically.

The issue with Hash Tables is that the memory required is higher than that of Binary Tree when we have large amount of data. So even if the search time in hashing is O(1), it will blast in space much higher as compared to Binary tree blasting in time when there are memory constraints.

But then theoretically, Hashing will give superior performance as compared to BST.

Share this content on your social channels -