Skip to content

Instantly share code, notes, and snippets.

@jwieder
Created December 16, 2014 22:01
Show Gist options
  • Save jwieder/f80ed669ecf85baed275 to your computer and use it in GitHub Desktop.
Save jwieder/f80ed669ecf85baed275 to your computer and use it in GitHub Desktop.
Example of linked list creation in C. Note this is merely a struct and function, and does not include a main function or preprocessor imperatives. Used in Harvard's CS50 class.
typedef struct node
{
int n;
struct node *next;
}
node;
bool search(int n, node* list)
{
node* ptr = list;
while (ptr != NULL)
{
if (ptr->n == n)
{
return true;
}
ptr = ptr->next;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment