Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- template <class Type>
- struct node
- {
- Type info;
- int indexX;
- int indexY;
- node<Type> *link;
- };
- template <class Type>
- class linkedList
- {
- public:
- node<Type> *head;
- linkedList(Type array[][3],int weidth,int height);
- void print();
- };
- template <class Type>
- linkedList<Type>::linkedList(Type array[][3],int weidth,int height){
- head=NULL;
- node <Type>* newnode;
- node <Type>*current=head;;
- for(int i=0;i<height;i++){
- for(int j=0;j<weidth;j++){
- if(current==NULL){
- newnode=new node<Type>;
- newnode->link=NULL;
- newnode->info=array[i][j];
- newnode->indexX=i;
- newnode->indexY=j;
- head=newnode;
- current=head;
- }else{
- while(current->link!=NULL){
- current=current->link;
- }
- newnode=new node<Type>;
- newnode->link=NULL;
- newnode->info=array[i][j];
- newnode->indexY=j;
- newnode->indexX=i;
- current->link=newnode;
- }
- }
- }
- }
- template <class Type>
- void linkedList<Type>::print(){
- node<Type>*current;
- for(current=head;current;current=current->link){
- std::cout<<"info"<<current->info<<" "<<current->indexY<<" "<<current->indexX<<std::endl;
- }
- }
- int main(){
- int d[3][3]={
- {2,1,3},
- {5,2,7},
- {6,3,8}
- };
- linkedList<int>list= linkedList<int>(d,3,3);
- list.print();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement