コード例 #1
0
ファイル: main.c プロジェクト: kalokshukla/LinkedLists
Node* sortedMergeRecursive(Node* a, Node* b) {
    Node *result=NULL;
    if (a==NULL) {
        return b;
    }
    if (b==NULL) {
        return a;
    }
    else {
        if (a->data <= b->data) {
            result=a;
            result->next=shuffleMergeRecursive(a->next, b);
        }
        else {
            result=b;
            result->next=shuffleMerge(a, b->next);
        }
        return result;
    }

}
コード例 #2
0
ファイル: linkedList.c プロジェクト: bpmnnit/codes
int main(){
  int c, n, r;
  do {
    printf("0.  Show\n");
    printf("1.  Append\n");
    printf("2.  Push\n");
    printf("3.  pop\n");
    printf("4.  Count Nodes\n");
    printf("5.  Get nth element\n");
    printf("6.  Delete List\n");
    printf("7.  Insert at nth index\n");
    printf("8.  InsertSort the List\n");
    printf("9.  FrontBackSplit\n");
    printf("10. Remove Duplicates\n");
    printf("11. Reverse the List\n");
    printf("12. Alternating Split\n");
    printf("13. Make a Dummy List\n");
    printf("14. Shuffle Merge\n");
    printf("15. EXIT\n");
    printf("Your Choice : ");
    scanf("%d", &c);
    switch(c){
      case 0 : show();
               break;
      case 1 : printf("Enter a number : ");
               scanf("%d", &n);
               append(n);
               break;
      case 2 : printf("Enter a number : ");
               scanf("%d", &n);
               push(n);
               break;         
      case 3 : if((r = pop()) > 0)
                 printf("%d\n", r);
               else
                 printf("List Empty\n");  
               break;
      case 4 : printf("%d\n", countNodes());
               break;
      case 5 : printf("Enter the index : ");
               scanf("%d", &n);
               ((r = getNth(n)) >= 0) ? printf("%d\n", r) : printf("Index out of Range\n");
               break;
      case 6 : deleteList();
               break;
      case 7 : printf("Enter the index and the number : ");
               scanf("%d%d", &r, &n);
               if(insertNth(r, n) < 0)
                 printf("Index out of Range. Aborting...");
               break;
      case 8 : insertSort();
               break;
      case 9 : frontBackSplit();
               break;
      case 10: removeDuplicate();
               break;
      case 11: reverse();
               break;
      case 12: alternatingSplit();
               break;    
      case 13: makeDummyList();
               break; 
      case 14: shuffleMerge();
               break;                                                                                           
      case 15: exit(0);         
      default: printf("wrong Choice\n");
               exit(0);                  
    }
  }while(c >= 0 && c <= 14);
}