Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<stdbool.h>
- typedef struct Database{
- int d;
- struct Database *n;
- }node;
- node *h;
- int main(){
- createList();
- printList();
- addData();
- printList();
- }
- void addData(){
- int a,b;
- printf("Enter The Desired Data : ");
- scanf("%d",&a);
- bool check=false;
- node *list=h;
- while(list){
- if(list->d==a){
- check=true;
- break;
- }
- list=list->n;
- }
- if(!check){
- printf("Data Not Found In Any Node\n");
- return;
- }
- printf("Enter The Data To Add : ");
- scanf("%d",&b);
- node *tmp=(node*)malloc(sizeof(node));
- tmp->d=b;
- tmp->n=list->n;
- list->n=tmp;
- }
- void createList(){
- node *list=(node*)malloc(sizeof(node));
- int a,b;
- printf("Enter Amount Of Node : ");
- scanf("%d",&a);
- printf("Enter Node 1 : ");
- scanf("%d",&b);
- list->d=b;
- list->n=NULL;
- h=list;
- loop(a-1);
- }
- void loop(int n){
- for(int i=1;i<=n;i++){
- printf("Enter Node %d : ",i+1);
- int a;
- scanf("%d",&a);
- addLast(a);
- }
- }
- void addLast(int a){
- node *list=h;
- while(list->n){
- list=list->n;
- }
- node *temp=(node*)malloc(sizeof(node));
- temp->d=a;
- temp->n=NULL;
- list->n=temp;
- }
- void printList(){
- node *list=h;
- while(list){
- printf("%d ",list->d);
- list=list->n;
- }
- printf("\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement