1

I am trying to implement reversing of linked list data structure using vectors and standard library.I am getting an error

‘::system’ has not been declared using ::system;

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
  vector<int> v[100];
  vector<int> v1;
  int n,i,k,j,x;
    cin>>n;
  for(i=0;i<n;i++){
    cin>>x;
    v1.push_back(x);
  }cout<<"Given linked list"<<endl;
  for(i=0;i<n;i++){
    cout<<"->"<<v1[i];
  }cout<<endl;
  cin>>k;
  j=0;
  for(i=0;i<n;i++){
    int y=v1[i];
    v[j].push_back(y);
    if((i+1)%k==0){
     j++;
    }
    }
  cout<<"Reversed Linked list"<<endl;
  for(i=0;i<=j;i++){
    reverse(v[i].begin(),v[i].end());
    for(k=0;k<v[i].size();k++){
      cout<<"->"<<v[i][k];
  }

  }

    return 0;
}
  • 6
    First please read [Why should I not #include ?](https://stackoverflow.com/questions/31816095/why-should-i-not-include-bits-stdc-h) Then read about [`std::reverse`](https://en.cppreference.com/w/cpp/algorithm/reverse). Then [get a few good books](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list/388282#388282) to read and learn C++ properly. – Some programmer dude Sep 16 '18 at 09:47
  • Just remove `#include ` – selbie Sep 16 '18 at 09:47
  • 2
    As for your error, *where* do you get the error? On which line? The code you show doesn't have any symbol `system` in it. – Some programmer dude Sep 16 '18 at 09:47
  • okay i will remove ,but as an alternative should i use , ,? – Ayush Mishra Sep 16 '18 at 09:49
  • 1
    `` and `` I think – john Sep 16 '18 at 09:50
  • 3
    But your code still has errors. In particular I really don't think you want `vector v[100];` that's an array of 100 empty vectors. Probably you want one vector of size 100 which would be `vector v(100);` or maybe just one empty vector which would be `vector v;` – john Sep 16 '18 at 09:52
  • I see that as the comments are being made the code is being editted. This gets very confusing. – john Sep 16 '18 at 09:56
  • I edited the code,and added new headers , . it still shows same error. – Ayush Mishra Sep 16 '18 at 09:56
  • @AyushMishra Well the crucial question is which line the error refers to. As you can see there is nothing called `system` in your posted code. So the error is hard to understand without more detail from you. – john Sep 16 '18 at 09:57
  • @john this is the line- **from main.cpp:4:/usr/include/c++/4.8/cstdlib:158:11:** – Ayush Mishra Sep 16 '18 at 09:59
  • OK, well that is not an error in your code, it refers to the header files not your code. It's either a) an error in the way your compiler has been installed, or b) an error in the way you are using your compiler. Again more details needed, but this has nothing at all to do with the code you have written. – john Sep 16 '18 at 10:01
  • 1
    If you want to traverse a list in reverse order, why don't you then simply iterate from `rbegin` to `rend` rather than from `begin` to `end`? Or construct a new list or vector from the reverse iterators? Seems to me that you are massively overcomplicating this. – Jesper Juhl Sep 16 '18 at 10:03
  • @jesper Juhl reversing of linked list from a particular key element – Ayush Mishra Sep 16 '18 at 10:07

0 Answers0