forked from ZoranPandovski/al-go-rithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'ZoranPandovski:master' into master
- Loading branch information
Showing
21 changed files
with
1,417 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
def GroupRotation(s, n): | ||
tem, res = [], "" | ||
for i in sorted(set(s.lower())): | ||
comb = [i for i in range(n) if s[i].lower() == s] | ||
print(comb) | ||
p = "" | ||
for i in comb: | ||
p += s[i] | ||
tem.append(p) | ||
m = len(tem) | ||
for i in range(m // 2): | ||
res += tem[i] + tem[-(i + 1)] | ||
if m % 2: | ||
res += tem[m // 2] | ||
return res | ||
|
||
if __name__ == "__main__": | ||
s = input() | ||
print(GroupRotation(s, len(s))) |
248 changes: 248 additions & 0 deletions
248
data_structures/Linked_list/C++/linked_list_by_ratnesh_maurya.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,248 @@ | ||
/* | ||
Author: Ratnesh Maurya | ||
Concept: Linked list implementation | ||
All rights reserved | ||
Github: https://github.com/ratnesh-maurya | ||
*/ | ||
|
||
|
||
|
||
|
||
|
||
#include<stdio.h> | ||
#include<stdlib.h> | ||
#include<malloc.h> | ||
struct node | ||
{ | ||
int data; | ||
struct node *next; | ||
}; | ||
struct node *start=NULL; | ||
struct node *create_ll(struct node *); | ||
struct node *display(struct node *); | ||
struct node *insert_beg(struct node *); | ||
struct node *insert_end(struct node *); | ||
struct node *insert_before(struct node *); | ||
struct node *insert_after(struct node*); | ||
struct node *delete_beg(struct node*); | ||
struct node *delete_end(struct node*); | ||
struct node *delete_before(struct node*); | ||
struct node *delete_after(struct node*); | ||
int main() | ||
{ | ||
int option; | ||
do | ||
{ | ||
printf("\n\n *****MAIN MENU *****"); | ||
printf("\n 1: Create a list"); | ||
printf("\n 2: Display the list"); | ||
printf("\n 3: Add a node at the beginning"); | ||
printf("\n 4: Add a node at the end"); | ||
printf("\n 5: Add a node before a given node"); | ||
printf("\n 6: Add a node after a given node"); | ||
printf("\n 7: Delete a node from the beginning"); | ||
printf("\n 8:delete a node from beginning "); | ||
printf("\n 9:delete a node from end "); | ||
printf("\n 10:delete a node before a given node"); | ||
printf("\n 11:delete a node after a given node"); | ||
printf("\n\n Enter your option : "); | ||
scanf("%d", &option); | ||
switch(option) | ||
{ | ||
case 1: start = create_ll(start); | ||
break; | ||
case 2: start = display(start); | ||
break; | ||
case 3: start = insert_beg(start); | ||
break; | ||
case 4: start = insert_end(start); | ||
break; | ||
case 5: start = insert_before(start); | ||
break; | ||
case 6: start = insert_after(start); | ||
break; | ||
case 8: start =delete_beg(start); | ||
break; | ||
case 9: start =delete_end(start); | ||
break; | ||
case 10: start =delete_before(start); | ||
break; | ||
case 11: start =delete_after(start); | ||
break; | ||
|
||
|
||
} | ||
} | ||
while(option !=12); | ||
return 0; | ||
} | ||
|
||
struct node *create_ll(struct node *start) | ||
{ | ||
struct node *new_node,*ptr; | ||
int num; | ||
printf("enter -1 to end\n"); | ||
printf(" enter the value of data:"); | ||
scanf("%d", &num); | ||
while(num!=-1 ) | ||
{ | ||
new_node = (struct node*)malloc(sizeof (struct node)); | ||
new_node -> data=num; | ||
if(start==NULL) | ||
{ | ||
new_node -> next = NULL; | ||
start = new_node; | ||
} | ||
else | ||
{ | ||
ptr = start; | ||
while (ptr->next!=NULL) | ||
ptr = ptr->next; | ||
ptr->next = new_node; | ||
new_node->next = NULL; | ||
} | ||
printf("\nenter the value of data : "); | ||
scanf("%d",&num); | ||
|
||
} | ||
return start; | ||
} | ||
struct node *display(struct node *start) | ||
{ | ||
struct node *ptr; | ||
ptr=start; | ||
while(ptr!= NULL) | ||
{ | ||
printf("\t%d",ptr->data); | ||
|
||
ptr = ptr->next; | ||
} | ||
|
||
return start; | ||
} | ||
struct node *insert_beg(struct node *start) | ||
{ | ||
struct node *new_node; | ||
int num; | ||
new_node=(struct node *)malloc(sizeof(struct node)); | ||
printf("\n enter the data inserted at beg:"); | ||
scanf("%d", &num ); | ||
new_node->data=num; | ||
new_node->next=start; | ||
start=new_node; | ||
display(start); | ||
return start; | ||
|
||
} | ||
struct node *insert_end(struct node *start) | ||
{ | ||
struct node *new_node,*ptr; | ||
int num; | ||
new_node=(struct node*)malloc(sizeof(struct node)); | ||
printf("\n enter the data inserted at end :"); | ||
scanf("%d", &num ); | ||
new_node->data=num; | ||
new_node->next=NULL; | ||
ptr=start; | ||
while(ptr->next!=NULL) | ||
ptr=ptr->next; | ||
ptr->next=new_node; | ||
display(start); | ||
return start; | ||
} | ||
struct node *insert_before(struct node *start) | ||
{ | ||
struct node *new_node,*ptr,*preptr; | ||
int num, val; | ||
new_node=(struct node*)malloc(sizeof(struct node)); | ||
printf("\nenter the data before which the newnode is to be inserted:"); | ||
scanf("%d",&val); | ||
printf("\nenter the data;"); | ||
scanf("%d", &num); | ||
new_node->data=num; | ||
ptr=start; | ||
while(ptr->data!=val) | ||
{ | ||
preptr=ptr; | ||
ptr=ptr->next; | ||
} | ||
preptr->next=new_node; | ||
new_node->next=ptr; | ||
display(start); | ||
return start; | ||
} | ||
struct node*insert_after(struct node *start) | ||
{ | ||
struct node *new_node,*ptr; | ||
int num,val; | ||
new_node=(struct node*)malloc(sizeof(struct node)); | ||
printf("\nenter the value after which data is inserted:"); | ||
scanf("%d", &val); | ||
printf("\n enter the value of data which is to be inseted"); | ||
scanf("%d",&num); | ||
new_node->data=num; | ||
ptr=start; | ||
while (ptr->data!=val) | ||
{ ptr=ptr->next; | ||
} | ||
new_node->next=ptr->next; | ||
ptr->next=new_node; | ||
display(start); | ||
return start; | ||
} | ||
struct node*delete_beg(struct node *start) | ||
{ | ||
struct node *ptr; | ||
ptr=start; | ||
start=start->next; | ||
free(ptr); | ||
display(start); | ||
return start; | ||
} | ||
struct node*delete_end(struct node *start) | ||
{ | ||
struct node *ptr,*preptr; | ||
ptr=start; | ||
while(ptr->next!=NULL) | ||
{ | ||
preptr=ptr; | ||
ptr=ptr->next; | ||
} | ||
preptr->next=NULL; | ||
free(ptr); | ||
return start; | ||
} | ||
struct node*delete_before(struct node *start) | ||
{ | ||
struct node *ptr,*preptr; | ||
int val; | ||
printf("\n enter the value of node before node to be deleted:"); | ||
scanf("%d",&val); | ||
ptr=start; | ||
while (ptr->next->data!=val) | ||
{ | ||
preptr=ptr; | ||
ptr=ptr->next; | ||
} | ||
preptr->next=ptr->next; | ||
free(ptr); | ||
display(start); | ||
} | ||
struct node*delete_after(struct node *start) | ||
{ | ||
struct node *ptr,*preptr; | ||
int val; | ||
printf("\n enter the value of node after node to be deleted:"); | ||
scanf("%d",&val); | ||
ptr=start; | ||
preptr=ptr; | ||
while (preptr->data!=val) | ||
{ | ||
preptr=ptr; | ||
ptr=ptr->next; | ||
} | ||
preptr->next=ptr->next; | ||
free(ptr); | ||
display(start); | ||
return(start); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
#include<stdio.h> | ||
#include<stdlib.h> | ||
#include<malloc.h> | ||
|
||
struct node | ||
{ | ||
int data ; | ||
struct node *next; | ||
}; | ||
|
||
struct node *start=NULL; | ||
struct node *create_ll(struct node * ); | ||
struct node *display(struct node *); | ||
struct node *reversedisplay(struct node *); | ||
|
||
int main() | ||
{ | ||
int option; | ||
do | ||
{ | ||
printf("\n\n***MAIN MENU***"); | ||
printf("\n 1:: CREATE THE LIST"); | ||
printf("\n 2:: DISPLAY NODE"); | ||
printf("\n 3:: REVERSE NODE"); | ||
printf("\n 11:: Exit "); | ||
printf("\n Enter the option : "); | ||
scanf("%d", &option); | ||
switch (option) | ||
{ | ||
case 1: start = create_ll(start); | ||
printf("/n LINKED LIST CREATED"); | ||
break; | ||
case 2: start = display(start); | ||
break; | ||
case 3: start = reversedisplay(start); | ||
break; | ||
} | ||
}while (option!=11); | ||
return 0; | ||
} | ||
|
||
struct node *create_ll(struct node *start) | ||
{ | ||
struct node *new_node,*ptr; | ||
int num; | ||
|
||
printf("\n Enter -1 to stop"); | ||
printf("\n ENTER the data :"); | ||
scanf("%d",&num); | ||
while (num!=-1) | ||
{ | ||
new_node= (struct node*)malloc(sizeof(struct node)); | ||
new_node->data=num; | ||
if (start==NULL) | ||
{ | ||
new_node->next=NULL; | ||
start=new_node; | ||
} | ||
else | ||
{ | ||
ptr = start; | ||
while (ptr->next!=NULL) | ||
ptr=ptr->next; | ||
ptr->next=new_node; | ||
new_node->next=NULL; | ||
} | ||
printf("\n Enter the data ::"); | ||
scanf("%d",&num); | ||
} | ||
return start; | ||
} | ||
|
||
struct node *display(struct node *start) | ||
{ | ||
struct node *ptr; | ||
ptr = start; | ||
int count =0; | ||
while(ptr != NULL) | ||
{ | ||
count = count +1; | ||
printf("\t%d", ptr -> data); | ||
ptr=ptr->next; | ||
} | ||
printf("\n NUMBER OF NODES== %d",count); | ||
return start; | ||
} | ||
|
||
struct node *reversedisplay(struct node *start) | ||
{ | ||
struct node *current=start; | ||
struct node *prev=NULL; | ||
struct node *temp; | ||
|
||
while (current !=NULL) | ||
{ | ||
temp=current->next; | ||
current->next=prev; | ||
prev = current; | ||
current= temp; | ||
} | ||
start= prev; | ||
display(start); | ||
|
||
} |
Oops, something went wrong.