Advertisement
Guest User

Untitled

a guest
Apr 28th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. template <class Type>
  4. struct node
  5. {
  6. Type info;
  7. int indexX;
  8. int indexY;
  9. node<Type> *link;
  10. };
  11.  
  12.  
  13.  
  14. template <class Type>
  15. class linkedList
  16. {
  17. public:
  18. node<Type> *head;
  19.  
  20. linkedList(Type array[][3],int weidth,int height);
  21. void print();
  22.  
  23.  
  24. };
  25. template <class Type>
  26. linkedList<Type>::linkedList(Type array[][3],int weidth,int height){
  27. head=NULL;
  28. node <Type>* newnode;
  29. node <Type>*current=head;;
  30. for(int i=0;i<height;i++){
  31. for(int j=0;j<weidth;j++){
  32. if(current==NULL){
  33. newnode=new node<Type>;
  34. newnode->link=NULL;
  35. newnode->info=array[i][j];
  36. newnode->indexX=i;
  37. newnode->indexY=j;
  38. head=newnode;
  39. current=head;
  40.  
  41. }else{
  42. while(current->link!=NULL){
  43. current=current->link;
  44. }
  45. newnode=new node<Type>;
  46. newnode->link=NULL;
  47. newnode->info=array[i][j];
  48. newnode->indexY=j;
  49. newnode->indexX=i;
  50. current->link=newnode;
  51.  
  52. }
  53.  
  54.  
  55. }
  56. }
  57.  
  58. }
  59. template <class Type>
  60. void linkedList<Type>::print(){
  61. node<Type>*current;
  62. for(current=head;current;current=current->link){
  63. std::cout<<"info"<<current->info<<" "<<current->indexY<<" "<<current->indexX<<std::endl;
  64. }
  65. }
  66. int main(){
  67. int d[3][3]={
  68. {2,1,3},
  69. {5,2,7},
  70. {6,3,8}
  71. };
  72. linkedList<int>list= linkedList<int>(d,3,3);
  73. list.print();
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement