Beispiel #1
0
int main()
{
    int flag;
    char  input[3];
    //creating 3 node type variables new_node current and head
    node *new_node,*current;
    //Dynamic initializtion
    new_node=(node *)malloc(sizeof(node));
    printf("\nEneter data to the node: ");
    //Storing some data
    scanf("%d",&new_node->data);
    //head pointing to the new node
    head=new_node;
    current=new_node;
    printf("\nDo you want to enter new node(yes/no):");
    scanf("%s",input);
    flag=string_test(input);
    //Iterate itself until flag is 1 i. the string entered is yes
    while(flag==1)
    {
        //calling create_node function to create new node and link it
        current=create_node(current);
        printf("\nDo you want to enter new node(yes/no):");
        scanf("%s",input);
        //calling string_test fuction to check whether the input is yes or no
        flag=string_test(input);
    }
    //Calling the display function and passing head as the value
    display(head);
    swaping();
    printf("\nAfter swaping");
    display(head);
    return 0;
}
int main()
{
    int m,k,j,flag;
    char  input[3];
    //creating 3 node type variables new_node current and head
    node *new_node,*current,*head=NULL;
    //Dynamic initializtion
    new_node=(node *)malloc(sizeof(node));
    printf("\nEneter data to the node: ");
    //Storing some data
    scanf("%d",&new_node->data);
    //head pointing to the new node
    head=new_node;
    current=new_node;
    length++;
    printf("\nDo you want to enter new node(yes/no):");
    scanf("%s",input);
    flag=string_test(input);
    //Iterate itself until flag is 1 i. the string entered is yes
    while(flag==1)
    {
        length++;
        //calling create_node function to create new node and link it
        current=create_node(current);
        printf("\nDo you want to enter new node(yes/no):");
        scanf("%s",input);
        //calling string_test fuction to check whether the input is yes or no
        flag=string_test(input);
    }
    //Calling the display function and passing head as the value
    display(head);
    printf("\nEnter the position of the node to swap from end and begining: ");
    scanf("%d",&m);
    if(m<length)
    {
        int j;
        j=m%2;
        if(j==0)
        {
            k=m/2;
        }
        if(m==k)
        {
            printf("\nPosition of node from end and begining is same so no changes in the linked list..");
            display(head);
        }
        else
            swaping(k,head);
    }
    else
        printf("\nThe position entered is greater than the length of the linked list");
    return 0;
}
void * scoresDescendingSort(struct student *students, int len) {
	if (students != NULL && len > 0){
		if (len == 1){
			return students;
		}
		else{
			for (int i = 0; i < len; i++){
				for (int j = i+1; j < len; j++){
					if (students[i].score < students[j].score){
						int temp = students[i].score;
						students[i].score = students[j].score;
						students[j].score = temp;
						swaping(students[i].name, students[j].name);
					}
				}
			}
			return students;
		}
	}
	else{
		return NULL;
	}
}