Question about learning C++ Linked Lists before Stacks....

In summary, it is important to understand linked lists before learning stacks and queues in C++. However, the way you learn these concepts can vary depending on how they are implemented. Linked lists allow for more flexible variable-sized stacks and queues, while simple fixed size stacks and queues can be implemented using pointers and an array. In general, it is important to understand the concept behind these data structures rather than focusing on the specific language being used.
  • #1
sukalp
53
2
i wanted to ask you that in c++it is important we should learn linked list before learning stack,queue that i wanted to know while studying data structures
 
Technology news on Phys.org
  • #2
I think it depends on whether the stacks and queues are implemented using linked lists or not.

Simple fixed size stacks and queues can be implemented using a couple of pointers and an array.

Linked lists allow for making more flexible variable sized stacks and queues.
 
  • Like
Likes FactChecker and QuantumQuest
  • #3
sukalp said:
i wanted to ask you that in c++it is important we should learn linked list before learning stack,queue that i wanted to know while studying data structures

Agree to jedishrfu. In general, things when learning C or C++, go the other way around (first simple stacks and queues using pointers then linked lists) which is equally effective. But, the way you describe can serve well too.
 
  • #4
QuantumQuest said:
Agree to jedishrfu. In general, things when learning C or C++, go the other way around (first simple stacks and queues using pointers then linked lists) which is equally effective. But, the way you describe can serve well too.

yes as linked list is not there in syllabus in our high school
i asked because there were programs given using linked list implemention of stack
so i asked we should know linked list before stack,queue
i got the answer
once again you solved mu confusion and doubt

thanks sir
 
  • #5
jedishrfu said:
I think it depends on whether the stacks and queues are implemented using linked lists or not.

Simple fixed size stacks and queues can be implemented using a couple of pointers and an array.

Linked lists allow for making more flexible variable sized stacks and queues.

okay sir
i understood
thanks you sir for clearing for confusion

once again thanks
your answer is helping me computer science in c++ in high school class 12
thanks
 
  • #6
The C++ is not relevant, the data structure is universal. As lon as you understand the concept, you can implement them in any language.

I doubt very many stacks are implemented with lists. You can really implement them in many different ways as long as they satisfy the criteria.
 
  • #7
newjerseyrunner said:
The C++ is not relevant, the data structure is universal. As lon as you understand the concept, you can implement them in any language.

I doubt very many stacks are implemented with lists. You can really implement them in many different ways as long as they satisfy the criteria.
yes right through array . pointers,structures
thanks
 

Related to Question about learning C++ Linked Lists before Stacks....

1. What is the difference between a linked list and a stack in C++?

A linked list is a data structure that consists of a sequence of nodes, where each node contains a value and a pointer to the next node in the list. A stack, on the other hand, is a data structure that follows the Last In First Out (LIFO) principle, meaning the last item inserted is the first one to be removed. In C++, a linked list can be implemented using pointers and dynamic memory allocation, while a stack can be implemented using either an array or linked list.

2. Why is it important to learn about linked lists before stacks in C++?

It is important to learn about linked lists before stacks in C++ because stacks are often implemented using linked lists. Understanding how linked lists work will give you a better understanding of how stacks are implemented and how to use them effectively.

3. How do you create and manipulate a linked list in C++?

To create a linked list in C++, you first need to define a structure that represents a node in the list. This structure should contain a data variable to hold the value and a pointer variable to point to the next node. Then, you can use the "new" keyword to dynamically allocate memory for each new node and link them together using the pointer variable. To manipulate a linked list, you can use various operations such as inserting, deleting, and searching for nodes.

4. What are some advantages of using linked lists over arrays in C++?

One advantage of linked lists over arrays is that linked lists can dynamically grow and shrink in size, while arrays have a fixed size. This makes linked lists more flexible and efficient for managing large amounts of data. Additionally, linked lists allow for efficient insertion and deletion of elements, which can be time-consuming and difficult with arrays.

5. Are there any drawbacks to using linked lists in C++?

One drawback of linked lists is that they use more memory compared to arrays. Linked lists require additional memory to store the pointers that link each node together. This can be a concern when dealing with large data sets. Additionally, accessing elements in a linked list can be slower compared to arrays, as elements cannot be accessed directly and must be traversed from the beginning of the list.

Similar threads

  • Programming and Computer Science
Replies
1
Views
744
  • Programming and Computer Science
4
Replies
107
Views
5K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
Replies
8
Views
911
  • Programming and Computer Science
Replies
22
Views
1K
  • Programming and Computer Science
Replies
1
Views
958
  • Programming and Computer Science
Replies
15
Views
1K
  • Programming and Computer Science
Replies
7
Views
698
  • Programming and Computer Science
Replies
16
Views
1K
Back
Top