Advertisement
apl-mhd

Bappy sir first assignment half done

Mar 15th, 2017
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.80 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. using namespace std;
  4.  
  5.  
  6. struct list{
  7.    int data;
  8.  
  9.    struct list *lNext;
  10.    struct list *rNext;
  11.    struct list *tNext;
  12.    struct list *bNext;
  13.  
  14. };
  15.  
  16. typedef struct list node;
  17.  
  18.  
  19. node *insertData(node *head, int sum[]){
  20.  
  21.     node *temp,*temp2, *rPrev, *lPrev, *tPrev, *bPrev;
  22.     int x;
  23.     rPrev = head;
  24.     lPrev = head;
  25.     tPrev = head;
  26.     bPrev = head;
  27.     int size;
  28.     cin>>size;
  29.  
  30. for(int i=0; i<size; i++){
  31.  
  32.         temp = new node();
  33.  
  34.     char check;
  35.     cin>>check;
  36.    
  37.     if(check== 'R'){
  38.    
  39.     cin>>x;
  40.     sum[0]+=x;
  41.     temp->data = x;
  42.     temp->rNext= NULL;
  43.  
  44.     rPrev->rNext = temp;
  45.     rPrev = temp;
  46.        
  47.  
  48.     }
  49.  
  50.     if(check == 'L'){
  51.  
  52.     cin>>x;
  53.     sum[1]+=x;
  54.     temp->data = x;
  55.     temp->rNext= NULL;
  56.  
  57.     lPrev->lNext = temp;
  58.     lPrev = temp;
  59.  
  60.     }
  61.  
  62.  
  63.       if(check== 'T'){
  64.          
  65.     cin>>x;
  66.     sum[2]+=x;
  67.     temp->data = x;
  68.     temp->tNext= NULL;
  69.  
  70.     tPrev->tNext = temp;
  71.     tPrev = temp;
  72.  
  73.     }
  74.  
  75.     if(check == 'B'){
  76.  
  77.     cin>>x;
  78.     sum[3]+=x;
  79.     temp->data = i;
  80.     temp->bNext= NULL;
  81.  
  82.     bPrev->bNext = temp;
  83.     bPrev = temp;
  84.  
  85.     }
  86.  
  87.  
  88.  
  89. }
  90.    return head;
  91. }
  92.  
  93. void display(node *head){
  94.  
  95.     node *temp;
  96.     temp = head;
  97.     while(temp->rNext !=NULL){
  98.  
  99.         printf("%d ", temp->rNext->data);
  100.         temp = temp->rNext;
  101.     }
  102.     cout<<endl;
  103.     temp = head;
  104.     while(temp->lNext !=NULL){
  105.  
  106.         printf("%d ", temp->lNext->data);
  107.         temp = temp->lNext;
  108.     }
  109.  
  110.      cout<<endl;
  111.      temp = head;
  112.     while(temp->tNext !=NULL){
  113.  
  114.         printf("%d ", temp->tNext->data);
  115.         temp = temp->tNext;
  116.     }
  117.     cout<<endl;
  118.     temp = head;
  119.     while(temp->bNext !=NULL){
  120.  
  121.         printf("%d ", temp->bNext->data);
  122.         temp = temp->bNext;
  123.     }
  124.  
  125.  
  126.  
  127. }
  128.  
  129. void largeLink(int sum[]){
  130.        
  131.        
  132.         int max=sum[0],address=0;
  133.         for(int i=0; i<4; i++){
  134.            
  135.             if(max <sum[i]){
  136.                 max = sum[i];
  137.            
  138.                 address =i;
  139.             }
  140.         }
  141.     //printf("%d = %d", address,max);
  142.        
  143.     if(address == 0)
  144.         printf("Right Link List Has Maximum Sum %d", max);
  145.    
  146.     if(address == 1)
  147.         printf("Left Link List Has Maximum Sum %d", max);
  148.    
  149.     if(address == 2)
  150.         printf("Top Link List Has Maximum Sum %d", max);
  151.    
  152.     if(address == 3)
  153.         printf("Bottom Link List Has Maximum Sum %d", max);
  154.    
  155. }
  156.  
  157.  
  158. int main()
  159. {
  160.     node *head, *temp, *temp2;
  161.    
  162.     int sum[4]={0}; /********************************************************** */
  163.                     /* | left| |right|  |top | Bottom| */
  164.     head = NULL;    /********************************************************** */
  165.  
  166.     head = new node();
  167.     //head->data = 10;
  168.  
  169.     head = insertData(head, sum);
  170.  
  171.     largeLink(sum);
  172.     //printf("%d %d %d %d",sum[0], sum[1], sum[2], sum[3]);
  173.    //display(head);
  174.  
  175.  
  176.  
  177.     return 0;
  178. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement