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. π
Replies
-
Jeffrey Arulrajcount me in i am in big trouble cos of data structures
-
Neeraj SharmaSure 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 KumarData 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 Arulrajcan you guys explain traversing of a list
-
optimystix@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
going to every item of list is traversing. Major use is find desired item in least time.jeffrey samuelcan you guys explain traversing of a list
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@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);
}
} -
vinod1993I 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. π
-
Vishal Sharma
The best way to understand is the "paper and pen" method.vinod1993I 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. π
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. -
simplycoderLinked 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
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.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
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.
You are reading an archived discussion.
Related Posts
how to get the voucher for that...if any info plz reply me.....thanqπ
While using RMC of grade M-30 or more at site, if at all the time taken to pour the concrete in the forms exceeds 3 hrs, should the concrete in...
I want to make a hovercraft, to participate in a competition.
it's size would be around 1mX1mX.5m
can anybody help me?
hello frieds
as we know that most of the IT companies in india provide consultancy services
like
wipro,tcs,accenture infosys etc
so can any one explain me what is consultancy services
Here's wishing all you Apple fans a happy iPhone 5 launch π
PS: For those of you who don't know who the bearded gentleman is... You don't need to be...