예제 #1
0
int main()
{
    int choice,data,pos;
    header=NULL;

    while(1)
    {
        system("cls");
        printf("\nSelect your choice: ");
        printf("\n1. Create List ");
        printf("\n2. Insert Node ");
        printf("\n3. Display List ");
        printf("\n4. Delete Node ");
        printf("\n5. Arrange in Ascending order");
        printf("\n6. Exit\n");
        scanf("%d",&choice);

        switch(choice)
        {
            case 1: create();
                    break;

            case 2: system("cls");
                    printf("\nSelect your choice: ");
                    printf("\n1. Insert at the End ");
                    printf("\n2. Insert at the Beginning ");
                    printf("\n3. Insert at a Specified Position ");
                    printf("\n4. Back to main menu\n");
                    scanf("%d",&choice);

                    switch(choice)
                    {
                    case 1: system("cls");
                            printf("\nEnter the data of the node: ");
                            scanf("%d",&data);
                            insert_end(data);
                            printf("\nNode inserted at the end of the list");
                            break;

                    case 2: system("cls");
                            printf("\nEnter the data of the node: ");
                            scanf("%d",&data);
                            insert_beg(data);
                            printf("\nNode inserted at the beginning of the list");
                            break;

                    case 3: system("cls");
                            printf("\nEnter the position at which you want to insert the node: ");
                            scanf("%d",&pos);
                            printf("\nEnter the data of the node: ");
                            scanf("%d",&data);
                            insert_pos(data,pos);
                            break;

                    case 4: break;

                    default: printf("Invalid choice!!");

                    }
                    break;

            case 3: display();
                    break;

            case 4: system("cls");
                    printf("\nSelect your choice: ");
                    printf("\n1. Delete from the End ");
                    printf("\n2. Delete from the Beginning ");
                    printf("\n3. Delete from a Specified Position ");
                    printf("\n4. Delete by the data of the node");
                    printf("\n5. Back to main menu\n");
                    scanf("%d",&choice);

                    switch(choice)
                    {
                    case 1: system("cls");
                            delete_end();
                            printf("\nNode deleted from the end of the list");
                            break;

                    case 2: system("cls");
                            delete_beg();
                            printf("\nNode deleted from the beginning of the list");
                            break;

                    case 3: system("cls");
                            printf("\nEnter the position at which you want to delete the node: ");
                            scanf("%d",&pos);
                            delete_pos(pos);
                            break;

                    case 4: system("cls");
                            printf("\nEnter the data which you want to delete: ");
                            scanf("%d",&data);
                            delete_val(data);
                            break;

                    case 5: break;

                    default: printf("Invalid choice!!");

                    }
                    break;

            case 5: ascend();
                    system("cls");
                    printf("\nList rearranged in ascending order");
                    getch();
                    break;

            case 6: exit(0);
                    break;

            default: printf("Invalid choice!!");
                     getch();

        }
    }
    return 0;
}
예제 #2
0
파일: Linked list.cpp 프로젝트: joyjitc/lab
 int main()
 {
    int ch;
    char ans = 'Y';

    while (ans == 'Y'||ans == 'y')
    {
        printf("\n---------------------------------\n");
        printf("\nOperations on singly linked list\n");
        printf("\n---------------------------------\n");
        printf("\n1.Insert node at first");
        printf("\n2.Insert node at last");
        printf("\n3.Insert node at position");
        printf("\n4.Sorted Linked List in Ascending Order");
        printf("\n5.Delete Node from any Position");
        printf("\n6.Update Node Value");
        printf("\n7.Search Element in the linked list");
        printf("\n8.Display List from Beginning to end");
        printf("\n9.Display List from end using Recursion");
        printf("\n10.Exit\n");
        printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
        printf("\nEnter your choice");
        scanf("%d", &ch);

        switch (ch)
        {
        case 1:
            printf("\n...Inserting node at first...\n");
            insert_node_first();
            break;
        case 2:
            printf("\n...Inserting node at last...\n");
            insert_node_last();
            break;
        case 3:
            printf("\n...Inserting node at position...\n");
            insert_node_pos();
            break;
        case 4:
            printf("\n...Sorted Linked List in Ascending Order...\n");
            sorted_ascend();
            break;
        case 5:
            printf("\n...Deleting Node from any Position...\n");
            delete_pos();
            break;
        case 6:
            printf("\n...Updating Node Value...\n");
            update_val();
            break;
        case 7:
            printf("\n...Searching Element in the List...\n");
            search();
            break;
        case 8:
            printf("\n...Displaying List From Beginning to End...\n");
            display();
            break;
        case 9:
            printf("\n...Displaying List From End using Recursion...\n");
            rev_display(first);
            break;
        case 10:
            printf("\n...Exiting...\n");
            return 0;
            break;
        default:
            printf("\n...Invalid Choice...\n");
            break;
        }
        printf("\nYOU WANT TO CONTINUE (Y/N)");
        scanf(" %c", &ans);
    }
    return 0;
 }