?
Solved

Linked List?

Posted on 2003-02-22
4
Medium Priority
?
183 Views
Last Modified: 2013-12-14
Hi, I can already make a linked list with 20 values inside. Now the problem is how to create two linked lists under one program? I have done so many researches but could not find any solution.

After that how to find the intersection between these two linked lists?
0
Comment
Question by:suprapto45
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 7

Expert Comment

by:burcarpat
ID: 8002218
why don't you try std::list?  if you do, then you can use std::set_intersection to find the intersection

see

    http://www.sgi.com/tech/stl/List.html

and

    http://www.sgi.com/tech/stl/set_intersection.html

for more information
0
 
LVL 16

Author Comment

by:suprapto45
ID: 8006510
Dear burcarpat,

I like your answer. Can you give one simple example for it and the points is yours. For example, can you give two lists perhaps using std::list that you specify and find the intersection amon them. The list needs only to have 2-3 data.

Thank you.
0
 
LVL 7

Accepted Solution

by:
burcarpat earned 160 total points
ID: 8006873
try this.  it's a simple example but it will get you started.  it should print out 2 and 3 as the answer

--- cut from here ---
#include <cstdlib>
#include <iostream>
#include <list>
#include <algorithm>


int
main(int    _argc,
     char*  _argv[]) {

  std::list<int> list1;
  list1.push_back(1);  
  list1.push_back(2);  
  list1.push_back(3);
   
  std::list<int> list2;
  list2.push_back(2);  
  list2.push_back(3);  
  list2.push_back(4);

  std::list<int> result(2);
 
  std::set_intersection(
    list1.begin(),
    list1.end(),
    list2.begin(),
    list2.end(),
    result.begin()
  );

  std::cout << "intersection:" << std::endl;
  for (std::list<int>::iterator iter = result.begin();
       iter != result.end(); ++iter) {
    std::cout << *iter << std::endl;
  };

  system("PAUSE");

  return 0;

}; // main
--- cut from here ---
0
 
LVL 16

Author Comment

by:suprapto45
ID: 8014585
Thank you burcapat.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question