1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
#include <stdio.h> #include <conio.h> typedef struct node // structure node { int info; // a information that is to be stored struct node *next; // create a next name pointer which will point to node type }node_t; // node_t object is created node_t *first,*rear,*printing; // first is for storing first information pointer // rear is to store where we have last stored the information // printing is to track while printing. void createlist(); // it create a empty list void insert_element_at_beg(int); // above funtion will create a new node and insert that into list // below function will create a new node and insert that into list void insert_element_at_end(int); // below function will create a new node and insert it after // at specific node if found else print node not found void insert_element_at_mid(); // below function will search the list void search_element(); // below function will delete an element void delete_element(); void print_list(); // it will print the list void main() { int info,choice,after; clrscr(); // create list at first createlist(); // loop till user wants to exit do { // ask user for choices printf("Enter your choice\n\n"); printf("Press 1 to Enter the Number at the begining\n"); printf("Press 2 to Enter the Number at the end\n"); printf("Press 3 to Enter the Number at mid\n"); printf("Press 4 to search an element\n"); printf("Press 5 to delete an element\n"); printf("Press 6 to Print the list\n"); printf("Press 7 to exit\n"); scanf("%d",&choice); // if one call insert_element() if(choice==1) { printf(" \n Enter the element"); scanf("%d",&info); insert_element_at_beg(info); } else if(choice==2){ printf("\n Enter the element"); scanf("%d",&info); insert_element_at_end(info); } else if(choice==3){ insert_element_at_mid(); } else if(choice==4){ search_element(); } else if(choice==5){ delete_element(); } else if(choice==6){ print_list(); // it will print the list printf("\n"); } } while(choice!=7); // if choice is 2 break the loop getch(); } void createlist() { node_t *createlist=malloc(sizeof(node_t)); // create a new node // intialize everyting with null createlist->next=NULL; createlist->info=NULL; // initialize first and rear with the first node created first=createlist; rear=createlist; } void search_element(){ int element,found=0; printing=rear; // check if list is empty if(rear->info==NULL){ printf("\nThe list is empty\n"); } else{ printf("Enter the element you want to search\n"); scanf("%d",&element); // search the element while(printing!=NULL){ if(printing->info==element) { found=1; // if element found than change the flag(found) break; } printing=printing->next; } if(found==0) printf("\nElement not found\n"); else printf("\nElement Found\n"); } } void insert_element_at_beg(int element) { node_t *new_node=malloc(sizeof(node_t)); // create a new node // check if list is empty // if yes then enter the first element if(first->info==NULL) { new_node->info=element; first->info=element; } // if not first node then // enter the info in newly created node and // point its next to our last created node. // and make our rear pointing to newly created node. else { new_node->info=element; new_node->next=rear; rear=new_node; } } void insert_element_at_end(int element){ node_t *new_node=malloc(sizeof(node_t)); // create a new node // check if list is empty // if yes then enter the first element if(first->info==NULL) { first->info=element; } // if not first node then // enter the info in newly created node and // point its next to our last created node. // and make our rear pointing to newly created node. else { new_node->info=element; new_node->next=NULL; first->next=new_node; first=new_node; } } void insert_element_at_mid(){ node_t *new_node=malloc(sizeof(node_t)); // create a new node int element,afterv; char choice1; if(first->info==NULL){ printf("\nList is empty. Add some numbers first\n"); } else{ printf("\n Enter the element after which you want to add\n"); scanf("%d",&afterv); printf("\n Enter the element which you wnat to add\n"); scanf("%d",&element); printing=rear; while(printing->info!=afterv){ printing=printing->next; if(printing==NULL) break; } if(printing==NULL){ printf("Element Not Found"); } else{ new_node->info=element; new_node->next=printing->next; printing->next=new_node; } } } // prints the whole list void print_list() { printing=rear; // intializes the printing // while loop -- until a node with next=null is not found while(printing!=NULL) { if(printing->next==NULL && printing->info==NULL){ printf("List is Empty"); } printf("%d ",printing->info); printing=printing->next; } } void delete_element(){ node_t *previous; // previous is created to store the previous node of match int element; printing=rear; // intialize print if(rear->info==NULL){ // check if list is empty printf("The list is empty"); } else{ printf("Enter the element you want to delete"); scanf("%d",&element); while(printing->info!=element && printing!=NULL){ // search the element previous=printing; printing=printing->next; } if(printing->info!=element){ // check element exist printf("Element not found"); } //if rear is equal to printing then the element to be //deleted is first in list else if(rear==printing){ rear=printing->next; } // if printing next is null then last element has to be deleted else if(printing->next==NULL){ first=previous; first->next=NULL; } // else delete matched mid element else{ previous->next=printing->next; } } } |
Java
Java Applet Of Moving Plane
“applet” class [crayon-5a2bba99973c8044557368/] HTML File [crayon-5a2bba99973d2988676214/] How to Run After compilation you can use “appletviewer” to run your applet. appletviewer xyz.html