Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 193
  • Last Modified:

Linked List?

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
suprapto45
Asked:
suprapto45
  • 2
  • 2
1 Solution
 
burcarpatCommented:
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
 
suprapto45Author Commented:
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
 
burcarpatCommented:
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
 
suprapto45Author Commented:
Thank you burcapat.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now